From 5e69a323430966096cc6c2b53561b449025a697a Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 7 Oct 2011 11:30:59 +0200 Subject: [PATCH] minissdpd: set SO_REUSEADDR on SSDP socket. see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=644511 --- minissdpd/Changelog.txt | 3 ++- minissdpd/openssdpsocket.c | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/minissdpd/Changelog.txt b/minissdpd/Changelog.txt index a375f2f..64342b9 100644 --- a/minissdpd/Changelog.txt +++ b/minissdpd/Changelog.txt @@ -1,7 +1,8 @@ -$Id: Changelog.txt,v 1.19 2011/07/30 13:16:22 nanard Exp $ +$Id: Changelog.txt,v 1.20 2011/10/07 09:21:19 nanard Exp $ 2011/10/07: unlink unix socket before binding. + set SO_REUSEADDR on SSDP socket. VERSION 1.1: diff --git a/minissdpd/openssdpsocket.c b/minissdpd/openssdpsocket.c index 1f2edff..5f1ce30 100644 --- a/minissdpd/openssdpsocket.c +++ b/minissdpd/openssdpsocket.c @@ -1,4 +1,4 @@ -/* $Id: openssdpsocket.c,v 1.7 2011/07/30 13:10:06 nanard Exp $ */ +/* $Id: openssdpsocket.c,v 1.8 2011/10/07 09:21:03 nanard Exp $ */ /* MiniUPnP project * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * (c) 2006-2011 Thomas Bernard @@ -143,8 +143,8 @@ OpenAndConfSSDPReceiveSocket(int n_listen_addr, int ipv6) { int s; + int opt = 1; #ifdef ENABLE_IPV6 - int on = 1; struct sockaddr_storage sockname; #else struct sockaddr_in sockname; @@ -167,7 +167,7 @@ OpenAndConfSSDPReceiveSocket(int n_listen_addr, { #ifdef IPV6_V6ONLY if(setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, - (char *)&on, sizeof(on)) < 0) + (char *)&opt, sizeof(opt)) < 0) { syslog(LOG_WARNING, "setsockopt(IPV6_V6ONLY): %m"); } @@ -197,6 +197,11 @@ OpenAndConfSSDPReceiveSocket(int n_listen_addr, sockname_len = sizeof(struct sockaddr_in); #endif + if(setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) + { + syslog(LOG_WARNING, "setsockopt(SO_REUSEADDR): %m"); + } + if(bind(s, (struct sockaddr *)&sockname, sockname_len) < 0) { syslog(LOG_ERR, "bind(udp%s): %m", ipv6 ? "6" : "");