From 8bc92bde34cedea1e4f58cb45fb74647494aadc2 Mon Sep 17 00:00:00 2001 From: Boris Lytochkin Date: Sat, 8 Apr 2017 23:00:23 +0300 Subject: [PATCH] choose IP(v6) address based on ipv6_ flag in a correct way --- src/tcp_address.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/tcp_address.cpp b/src/tcp_address.cpp index 08161fe3..5ccb1178 100644 --- a/src/tcp_address.cpp +++ b/src/tcp_address.cpp @@ -147,7 +147,7 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_ } const int family = ifr.ifr_addr.sa_family; - if ((family == AF_INET || (ipv6_ && family == AF_INET6)) + if (family == (ipv6_ ? AF_INET6 : AF_INET) && !strcmp (nic_, ifr.ifr_name)) { if (is_src_) @@ -210,7 +210,7 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_ continue; const int family = ifp->ifa_addr->sa_family; - if ((family == AF_INET || (ipv6_ && family == AF_INET6)) + if (family == (ipv6_ ? AF_INET6 : AF_INET) && !strcmp (nic_, ifp->ifa_name)) { if (is_src_) memcpy (&source_address, ifp->ifa_addr, @@ -338,9 +338,7 @@ int zmq::tcp_address_t::resolve_nic_name(const char *nic_, bool ipv6_, bool is_s while (current_unicast_address) { ADDRESS_FAMILY family = current_unicast_address->Address.lpSockaddr->sa_family; - if (family == AF_INET || - (ipv6_ && family == AF_INET6) - ) { + if (family == (ipv6_ ? AF_INET6 : AF_INET)) { if (is_src_) memcpy(&source_address, current_unicast_address->Address.lpSockaddr, (family == AF_INET) ? sizeof(struct sockaddr_in)