From: Florian Forster Date: Mon, 5 Apr 2010 14:20:34 +0000 (+0200) Subject: Build system: Check for "struct ip_mreqn". X-Git-Tag: collectd-4.10.0~24 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=76489692cb9eef2590d8280a3cefad1c9f9244a2;p=collectd.git Build system: Check for "struct ip_mreqn". Use this rather than hard-coding "if Linux …" --- diff --git a/configure.in b/configure.in index c2cb5d61..b5ce7812 100644 --- a/configure.in +++ b/configure.in @@ -971,6 +971,13 @@ AC_CHECK_MEMBERS([struct net_device_stats.rx_bytes, struct net_device_stats.tx_p #include ]) +AC_CHECK_MEMBERS([struct ip_mreqn.imr_ifindex], [], + [], + [ + #include + #include + ]) + AC_CHECK_MEMBERS([struct kinfo_proc.ki_pid, struct kinfo_proc.ki_rssize, struct kinfo_proc.ki_rusage], [ AC_DEFINE(HAVE_STRUCT_KINFO_PROC_FREEBSD, 1, diff --git a/src/network.c b/src/network.c index b1b9e398..6d0381b7 100644 --- a/src/network.c +++ b/src/network.c @@ -1600,17 +1600,23 @@ static int network_set_interface (const sockent_t *se, const struct addrinfo *ai if (IN_MULTICAST (ntohl (addr->sin_addr.s_addr))) { -#if KERNEL_LINUX +#if HAVE_STRUCT_IP_MREQN_IMR_IFINDEX + /* If possible, use the "ip_mreqn" structure which has + * an "interface index" member. Using the interface + * index is preferred here, because of its similarity + * to the way IPv6 handles this. Unfortunately, it + * appears not to be portable. */ struct ip_mreqn mreq; -#else - struct ip_mreq mreq; -#endif + memset (&mreq, 0, sizeof (mreq)); mreq.imr_multiaddr.s_addr = addr->sin_addr.s_addr; -#if KERNEL_LINUX mreq.imr_address.s_addr = ntohl (INADDR_ANY); mreq.imr_ifindex = se->interface; #else + struct ip_mreq mreq; + + memset (&mreq, 0, sizeof (mreq)); + mreq.imr_multiaddr.s_addr = addr->sin_addr.s_addr; mreq.imr_interface.s_addr = ntohl (INADDR_ANY); #endif @@ -1701,7 +1707,7 @@ static int network_bind_socket (int fd, const struct addrinfo *ai, const int int struct sockaddr_in *addr = (struct sockaddr_in *) ai->ai_addr; if (IN_MULTICAST (ntohl (addr->sin_addr.s_addr))) { -#if KERNEL_LINUX +#if HAVE_STRUCT_IP_MREQN_IMR_IFINDEX struct ip_mreqn mreq; #else struct ip_mreq mreq; @@ -1710,7 +1716,10 @@ static int network_bind_socket (int fd, const struct addrinfo *ai, const int int DEBUG ("fd = %i; IPv4 multicast address found", fd); mreq.imr_multiaddr.s_addr = addr->sin_addr.s_addr; -#if KERNEL_LINUX +#if HAVE_STRUCT_IP_MREQN_IMR_IFINDEX + /* Set the interface using the interface index if + * possible (available). Unfortunately, the struct + * ip_mreqn is not portable. */ mreq.imr_address.s_addr = ntohl (INADDR_ANY); mreq.imr_ifindex = interface_idx; #else