diff --git a/configure.ac b/configure.ac index 414ae08..42f4f9a 100644 --- a/configure.ac +++ b/configure.ac @@ -69,6 +69,34 @@ AC_FUNC_FORK AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK AC_CHECK_FUNCS([gethostname getifaddrs gettimeofday inet_ntoa memmove memset mkdir realpath select sendfile setlocale socket strcasecmp strchr strdup strerror strncasecmp strpbrk strrchr strstr strtol strtoul]) +# +# Check for struct ip_mreqn +# +AC_MSG_CHECKING(for struct ip_mreqn) +AC_TRY_COMPILE([#include ], [ + struct ip_mreqn mreq; + mreq.imr_address.s_addr = 0; +], [ + # Yes, we have it... + AC_MSG_RESULT(yes) + AC_DEFINE([HAVE_STRUCT_IP_MREQN],[],[Support for struct ip_mreqn]) +], [ + # We'll just have to try and use struct ip_mreq + AC_MSG_RESULT(no) + AC_MSG_CHECKING(for struct ip_mreq) + AC_TRY_COMPILE([#include ], [ + struct ip_mreq mreq; + mreq.imr_interface.s_addr = 0; + ], [ + # Yes, we have it... + AC_MSG_RESULT(yes) + AC_DEFINE([HAVE_STRUCT_IP_MREQ],[],[Support for struct ip_mreq]) + ], [ + # No multicast support + AC_MSG_ERROR([No multicast support]) + ]) +]) + ################################################################################################################ # Special include directories case $host in diff --git a/getifaddr.c b/getifaddr.c index c927c5e..b737947 100644 --- a/getifaddr.c +++ b/getifaddr.c @@ -95,6 +95,7 @@ getifaddr(const char *ifname, int notify) } addr_in = (struct sockaddr_in *)p->ifa_netmask; memcpy(&lan_addr[n_lan_addr].mask, &addr_in->sin_addr, sizeof(lan_addr[n_lan_addr].mask)); + lan_addr[n_lan_addr].ifindex = if_nametoindex(p->ifa_name); lan_addr[n_lan_addr].snotify = OpenAndConfSSDPNotifySocket(lan_addr[n_lan_addr].addr.s_addr); if (lan_addr[n_lan_addr].snotify >= 0) { @@ -154,6 +155,7 @@ getifaddr(const char *ifname, int notify) continue; memcpy(&addr, &(ifr->ifr_addr), sizeof(addr)); memcpy(&lan_addr[n_lan_addr].mask, &addr.sin_addr, sizeof(addr)); + lan_addr[n_lan_addr].ifindex = if_nametoindex(ifr->ifr_name); lan_addr[n_lan_addr].snotify = OpenAndConfSSDPNotifySocket(lan_addr[i].addr.s_addr); if (lan_addr[n_lan_addr].snotify >= 0) { @@ -313,15 +315,11 @@ reload_ifaces(int notify) } n_lan_addr = 0; - if (runtime_vars.ifaces[0]) - { - for (i = 0; runtime_vars.ifaces[i]; i++) - { - getifaddr(runtime_vars.ifaces[i], notify); - } - } - else - getifaddr(NULL, notify); + i = 0; + do { + getifaddr(runtime_vars.ifaces[i], notify); + i++; + } while (runtime_vars.ifaces[i]); for (i = 0; i < n_lan_addr; i++) { diff --git a/minidlnatypes.h b/minidlnatypes.h index 8dff040..9cee2a3 100644 --- a/minidlnatypes.h +++ b/minidlnatypes.h @@ -42,6 +42,7 @@ struct lan_addr_s { struct in_addr addr; /* ip */ struct in_addr mask; /* netmask */ int snotify; /* notify socket */ + unsigned int ifindex; /* interface index */ }; struct runtime_vars_s { diff --git a/minissdp.c b/minissdp.c index 8b6a76e..9dd946e 100644 --- a/minissdp.c +++ b/minissdp.c @@ -57,15 +57,20 @@ #define SSDP_MCAST_ADDR ("239.255.255.250") static int -AddMulticastMembership(int s, in_addr_t ifaddr) +AddMulticastMembership(int s, struct lan_addr_s *iface) { - struct ip_mreq imr; /* Ip multicast membership */ - +#ifdef HAVE_STRUCT_IP_MREQN + struct ip_mreqn imr; /* Ip multicast membership */ /* setting up imr structure */ imr.imr_multiaddr.s_addr = inet_addr(SSDP_MCAST_ADDR); - imr.imr_interface.s_addr = ifaddr; - - if (setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&imr, sizeof(struct ip_mreq)) < 0) + imr.imr_ifindex = iface->ifindex; +#else + struct ip_mreq imr; /* Ip multicast membership */ + /* setting up imr structure */ + 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) { DPRINTF(E_ERROR, L_SSDP, "setsockopt(udp, IP_ADD_MEMBERSHIP): %s\n", strerror(errno)); return -1; @@ -106,11 +111,9 @@ OpenAndConfSSDPReceiveSocket(void) return -1; } - i = n_lan_addr; - while (i > 0) + for (i = n_lan_addr; i > 0; i--) { - i--; - if (AddMulticastMembership(s, lan_addr[i].addr.s_addr) < 0) + if (AddMulticastMembership(s, &lan_addr[i]) < 0) { DPRINTF(E_WARN, L_SSDP, "Failed to add multicast membership for address %s\n", diff --git a/upnpsoap.c b/upnpsoap.c index deb1c45..df5e49f 100644 --- a/upnpsoap.c +++ b/upnpsoap.c @@ -527,7 +527,7 @@ parse_sort_criteria(char *sortCriteria, int *error) str.data = order; str.size = 4096; str.off = 0; - strcatf(&str, "order by "); + strcatf(&str, "order by "); } for( i=0; item != NULL; i++ ) {