diff --git a/src/reflector.c b/src/reflector.c index 4ca6565..7666be0 100644 --- a/src/reflector.c +++ b/src/reflector.c @@ -65,10 +65,15 @@ int new_recv_socket(const struct sockaddr_storage *sa, socklen_t sa_len, uint32_ log_err(LOG_ERR, "IPv6 setsockopt IPV6_PKTINFO"); goto cleanup; } -#if defined(SO_BINDTODEVICE) +#if defined(IPV6_BOUND_IF) + if (setsockopt(fd, IPPROTO_IPV6, IPV6_BOUND_IF, &ifindex, sizeof(ifindex)) == -1) { + log_err(LOG_ERR, "IPv6 setsockopt IPV6_BOUND_IF"); + goto cleanup; + } +#elif defined(SO_BINDTODEVICE) { struct ifreq ifr; - if (if_indextoname(ifindex, ifr.ifr_ifrn.ifrn_name) == NULL) { + if (if_indextoname(ifindex, ifr.ifr_name) == NULL) { log_err(LOG_ERR, "if_indextoname"); goto cleanup; } @@ -77,11 +82,6 @@ int new_recv_socket(const struct sockaddr_storage *sa, socklen_t sa_len, uint32_ goto cleanup; } } -#elif defined(IPV6_BOUND_IF) - if (setsockopt(fd, IPPROTO_IPV6, IPV6_BOUND_IF, &ifindex, sizeof(ifindex)) == -1) { - log_err(LOG_ERR, "IPv6 setsockopt IPV6_BOUND_IF"); - goto cleanup; - } #endif break; case AF_INET: @@ -101,10 +101,15 @@ int new_recv_socket(const struct sockaddr_storage *sa, socklen_t sa_len, uint32_ goto cleanup; } #endif -#if defined(SO_BINDTODEVICE) +#if defined(IP_BOUND_IF) + if (setsockopt(fd, IPPROTO_IP, IP_BOUND_IF, &ifindex, sizeof(ifindex)) == -1) { + log_err(LOG_ERR, "IPv4 setsockopt IP_BOUND_IF"); + goto cleanup; + } +#elif defined(SO_BINDTODEVICE) { struct ifreq ifr; - if (if_indextoname(ifindex, ifr.ifr_ifrn.ifrn_name) == NULL) { + if (if_indextoname(ifindex, ifr.ifr_name) == NULL) { log_err(LOG_ERR, "if_indextoname"); goto cleanup; } @@ -113,11 +118,6 @@ int new_recv_socket(const struct sockaddr_storage *sa, socklen_t sa_len, uint32_ goto cleanup; } } -#elif defined(IP_BOUND_IF) - if (setsockopt(fd, IPPROTO_IP, IP_BOUND_IF, &ifindex, sizeof(ifindex)) == -1) { - log_err(LOG_ERR, "IPv4 setsockopt IP_BOUND_IF"); - goto cleanup; - } #endif break; default: