minissdp: Use struct ip_mreqn for multicast membership if it's available.
This commit is contained in:
parent
1e7fe1413c
commit
a3252bd2dd
28
configure.ac
28
configure.ac
@ -69,6 +69,34 @@ AC_FUNC_FORK
|
|||||||
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
|
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])
|
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 <netinet/in.h>], [
|
||||||
|
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 <netinet/in.h>], [
|
||||||
|
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
|
# Special include directories
|
||||||
case $host in
|
case $host in
|
||||||
|
16
getifaddr.c
16
getifaddr.c
@ -95,6 +95,7 @@ getifaddr(const char *ifname, int notify)
|
|||||||
}
|
}
|
||||||
addr_in = (struct sockaddr_in *)p->ifa_netmask;
|
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));
|
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);
|
lan_addr[n_lan_addr].snotify = OpenAndConfSSDPNotifySocket(lan_addr[n_lan_addr].addr.s_addr);
|
||||||
if (lan_addr[n_lan_addr].snotify >= 0)
|
if (lan_addr[n_lan_addr].snotify >= 0)
|
||||||
{
|
{
|
||||||
@ -154,6 +155,7 @@ getifaddr(const char *ifname, int notify)
|
|||||||
continue;
|
continue;
|
||||||
memcpy(&addr, &(ifr->ifr_addr), sizeof(addr));
|
memcpy(&addr, &(ifr->ifr_addr), sizeof(addr));
|
||||||
memcpy(&lan_addr[n_lan_addr].mask, &addr.sin_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);
|
lan_addr[n_lan_addr].snotify = OpenAndConfSSDPNotifySocket(lan_addr[i].addr.s_addr);
|
||||||
if (lan_addr[n_lan_addr].snotify >= 0)
|
if (lan_addr[n_lan_addr].snotify >= 0)
|
||||||
{
|
{
|
||||||
@ -313,15 +315,11 @@ reload_ifaces(int notify)
|
|||||||
}
|
}
|
||||||
n_lan_addr = 0;
|
n_lan_addr = 0;
|
||||||
|
|
||||||
if (runtime_vars.ifaces[0])
|
i = 0;
|
||||||
{
|
do {
|
||||||
for (i = 0; runtime_vars.ifaces[i]; i++)
|
getifaddr(runtime_vars.ifaces[i], notify);
|
||||||
{
|
i++;
|
||||||
getifaddr(runtime_vars.ifaces[i], notify);
|
} while (runtime_vars.ifaces[i]);
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
getifaddr(NULL, notify);
|
|
||||||
|
|
||||||
for (i = 0; i < n_lan_addr; i++)
|
for (i = 0; i < n_lan_addr; i++)
|
||||||
{
|
{
|
||||||
|
@ -42,6 +42,7 @@ struct lan_addr_s {
|
|||||||
struct in_addr addr; /* ip */
|
struct in_addr addr; /* ip */
|
||||||
struct in_addr mask; /* netmask */
|
struct in_addr mask; /* netmask */
|
||||||
int snotify; /* notify socket */
|
int snotify; /* notify socket */
|
||||||
|
unsigned int ifindex; /* interface index */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct runtime_vars_s {
|
struct runtime_vars_s {
|
||||||
|
23
minissdp.c
23
minissdp.c
@ -57,15 +57,20 @@
|
|||||||
#define SSDP_MCAST_ADDR ("239.255.255.250")
|
#define SSDP_MCAST_ADDR ("239.255.255.250")
|
||||||
|
|
||||||
static int
|
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 */
|
/* setting up imr structure */
|
||||||
imr.imr_multiaddr.s_addr = inet_addr(SSDP_MCAST_ADDR);
|
imr.imr_multiaddr.s_addr = inet_addr(SSDP_MCAST_ADDR);
|
||||||
imr.imr_interface.s_addr = ifaddr;
|
imr.imr_ifindex = iface->ifindex;
|
||||||
|
#else
|
||||||
if (setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&imr, sizeof(struct ip_mreq)) < 0)
|
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));
|
DPRINTF(E_ERROR, L_SSDP, "setsockopt(udp, IP_ADD_MEMBERSHIP): %s\n", strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
@ -106,11 +111,9 @@ OpenAndConfSSDPReceiveSocket(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = n_lan_addr;
|
for (i = n_lan_addr; i > 0; i--)
|
||||||
while (i > 0)
|
|
||||||
{
|
{
|
||||||
i--;
|
if (AddMulticastMembership(s, &lan_addr[i]) < 0)
|
||||||
if (AddMulticastMembership(s, lan_addr[i].addr.s_addr) < 0)
|
|
||||||
{
|
{
|
||||||
DPRINTF(E_WARN, L_SSDP,
|
DPRINTF(E_WARN, L_SSDP,
|
||||||
"Failed to add multicast membership for address %s\n",
|
"Failed to add multicast membership for address %s\n",
|
||||||
|
@ -527,7 +527,7 @@ parse_sort_criteria(char *sortCriteria, int *error)
|
|||||||
str.data = order;
|
str.data = order;
|
||||||
str.size = 4096;
|
str.size = 4096;
|
||||||
str.off = 0;
|
str.off = 0;
|
||||||
strcatf(&str, "order by ");
|
strcatf(&str, "order by ");
|
||||||
}
|
}
|
||||||
for( i=0; item != NULL; i++ )
|
for( i=0; item != NULL; i++ )
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user