minissdpd: set SO_REUSEADDR on SSDP socket.

see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=644511
This commit is contained in:
Thomas Bernard 2011-10-07 11:30:59 +02:00
parent fd96a3ddcd
commit 5e69a32343
2 changed files with 10 additions and 4 deletions

View File

@ -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: 2011/10/07:
unlink unix socket before binding. unlink unix socket before binding.
set SO_REUSEADDR on SSDP socket.
VERSION 1.1: VERSION 1.1:

View File

@ -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 /* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2011 Thomas Bernard * (c) 2006-2011 Thomas Bernard
@ -143,8 +143,8 @@ OpenAndConfSSDPReceiveSocket(int n_listen_addr,
int ipv6) int ipv6)
{ {
int s; int s;
int opt = 1;
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
int on = 1;
struct sockaddr_storage sockname; struct sockaddr_storage sockname;
#else #else
struct sockaddr_in sockname; struct sockaddr_in sockname;
@ -167,7 +167,7 @@ OpenAndConfSSDPReceiveSocket(int n_listen_addr,
{ {
#ifdef IPV6_V6ONLY #ifdef IPV6_V6ONLY
if(setsockopt(s, IPPROTO_IPV6, 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"); syslog(LOG_WARNING, "setsockopt(IPV6_V6ONLY): %m");
} }
@ -197,6 +197,11 @@ OpenAndConfSSDPReceiveSocket(int n_listen_addr,
sockname_len = sizeof(struct sockaddr_in); sockname_len = sizeof(struct sockaddr_in);
#endif #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) if(bind(s, (struct sockaddr *)&sockname, sockname_len) < 0)
{ {
syslog(LOG_ERR, "bind(udp%s): %m", ipv6 ? "6" : ""); syslog(LOG_ERR, "bind(udp%s): %m", ipv6 ? "6" : "");