From 4236d53b5908edf241e86dc49fecab5edcce3943 Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Wed, 26 Feb 2014 15:09:21 -0800 Subject: [PATCH] ssdp: add multicast membership as the individual interfaces come up Previously, this was only done during startup, so interfaces that came up later wouldn't have been added. --- minissdp.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/minissdp.c b/minissdp.c index cf4d922..4f99444 100644 --- a/minissdp.c +++ b/minissdp.c @@ -59,6 +59,7 @@ static int AddMulticastMembership(int s, struct lan_addr_s *iface) { + int ret; #ifdef HAVE_STRUCT_IP_MREQN struct ip_mreqn imr; /* Ip multicast membership */ /* setting up imr structure */ @@ -70,9 +71,11 @@ AddMulticastMembership(int s, struct lan_addr_s *iface) imr.imr_multiaddr.s_addr = inet_addr(SSDP_MCAST_ADDR); imr.imr_interface.s_addr = iface->addr.s_addr; #endif - if (setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&imr, sizeof(imr)) < 0) + ret = setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&imr, sizeof(imr)); + if (ret < 0 && errno != EADDRINUSE) { - DPRINTF(E_ERROR, L_SSDP, "setsockopt(udp, IP_ADD_MEMBERSHIP): %s\n", strerror(errno)); + DPRINTF(E_ERROR, L_SSDP, "setsockopt(udp, IP_ADD_MEMBERSHIP): %s\n", + strerror(errno)); return -1; } @@ -111,16 +114,6 @@ OpenAndConfSSDPReceiveSocket(void) return -1; } - for (i = 0; i < n_lan_addr; i++) - { - if (AddMulticastMembership(s, &lan_addr[i]) < 0) - { - DPRINTF(E_WARN, L_SSDP, - "Failed to add multicast membership for address %s\n", - lan_addr[i].str ); - } - } - return s; } @@ -179,6 +172,12 @@ OpenAndConfSSDPNotifySocket(struct lan_addr_s *iface) return -1; } + if (AddMulticastMembership(sssdp, iface) < 0) + { + DPRINTF(E_WARN, L_SSDP, "Failed to add multicast membership for address %s\n", + iface->str); + } + return s; }