Commit f4473869 authored by Martin Hurton's avatar Martin Hurton

Style fixes

parent c6e38ec1
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
#define AI_ADDRCONFIG 0 #define AI_ADDRCONFIG 0
#endif #endif
#if defined ZMQ_HAVE_SOLARIS #ifdef ZMQ_HAVE_SOLARIS
#include <sys/sockio.h> #include <sys/sockio.h>
#include <net/if.h> #include <net/if.h>
...@@ -56,7 +56,7 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_ ...@@ -56,7 +56,7 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_
(void) ipv6_; (void) ipv6_;
// Create a socket. // Create a socket.
int fd = open_socket (AF_INET, SOCK_DGRAM, 0); const int fd = open_socket (AF_INET, SOCK_DGRAM, 0);
errno_assert (fd != -1); errno_assert (fd != -1);
// Retrieve number of interfaces. // Retrieve number of interfaces.
...@@ -67,7 +67,7 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_ ...@@ -67,7 +67,7 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_
errno_assert (rc != -1); errno_assert (rc != -1);
// Allocate memory to get interface names. // Allocate memory to get interface names.
size_t ifr_size = sizeof (struct lifreq) * ifn.lifn_count; const size_t ifr_size = sizeof (struct lifreq) * ifn.lifn_count;
char *ifr = (char*) malloc (ifr_size); char *ifr = (char*) malloc (ifr_size);
alloc_assert (ifr); alloc_assert (ifr);
...@@ -83,17 +83,16 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_ ...@@ -83,17 +83,16 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_
// Find the interface with the specified name and AF_INET family. // Find the interface with the specified name and AF_INET family.
bool found = false; bool found = false;
lifreq *ifrp = ifc.lifc_req; lifreq *ifrp = ifc.lifc_req;
for (int n = 0; n < (int) (ifc.lifc_len / sizeof (lifreq)); for (int n = 0; n < (int) (ifc.lifc_len / sizeof lifreq);
n ++, ifrp ++) { n ++, ifrp ++) {
if (!strcmp (nic_, ifrp->lifr_name)) { if (!strcmp (nic_, ifrp->lifr_name)) {
rc = ioctl (fd, SIOCGLIFADDR, (char*) ifrp); rc = ioctl (fd, SIOCGLIFADDR, (char*) ifrp);
errno_assert (rc != -1); errno_assert (rc != -1);
if (ifrp->lifr_addr.ss_family == AF_INET) { if (ifrp->lifr_addr.ss_family == AF_INET) {
if (is_src_) { if (is_src_)
source_address.ipv4 = *(sockaddr_in*) &ifrp->lifr_addr; source_address.ipv4 = *(sockaddr_in*) &ifrp->lifr_addr;
} else { else
address.ipv4 = *(sockaddr_in*) &ifrp->lifr_addr; address.ipv4 = *(sockaddr_in*) &ifrp->lifr_addr;
}
found = true; found = true;
break; break;
} }
...@@ -130,7 +129,7 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_ ...@@ -130,7 +129,7 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_
struct ifreq ifr; struct ifreq ifr;
// Copy interface name for ioctl get. // Copy interface name for ioctl get.
strncpy (ifr.ifr_name, nic_, sizeof (ifr.ifr_name)); strncpy (ifr.ifr_name, nic_, sizeof ifr.ifr_name);
// Fetch interface address. // Fetch interface address.
int rc = ioctl (sd, SIOCGIFADDR, (caddr_t) &ifr, sizeof (struct ifreq)); int rc = ioctl (sd, SIOCGIFADDR, (caddr_t) &ifr, sizeof (struct ifreq));
...@@ -142,13 +141,12 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_ ...@@ -142,13 +141,12 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_
errno = ENODEV; errno = ENODEV;
return -1; return -1;
} }
if (is_src_) { if (is_src_)
memcpy (&source_address.ipv4.sin_addr, &((sockaddr_in*) &ifr.ifr_addr)->sin_addr, memcpy (&source_address.ipv4.sin_addr, &((sockaddr_in*) &ifr.ifr_addr)->sin_addr,
sizeof (in_addr)); sizeof in_addr);
} else { else
memcpy (&address.ipv4.sin_addr, &((sockaddr_in*) &ifr.ifr_addr)->sin_addr, memcpy (&address.ipv4.sin_addr, &((sockaddr_in*) &ifr.ifr_addr)->sin_addr,
sizeof (in_addr)); sizeof in_addr);
}
return 0; return 0;
} }
...@@ -172,23 +170,21 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_ ...@@ -172,23 +170,21 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_
// Find the corresponding network interface. // Find the corresponding network interface.
bool found = false; bool found = false;
for (ifaddrs *ifp = ifa; ifp != NULL ;ifp = ifp->ifa_next) for (ifaddrs *ifp = ifa; ifp != NULL; ifp = ifp->ifa_next) {
{
if (ifp->ifa_addr == NULL) if (ifp->ifa_addr == NULL)
continue; continue;
int family = ifp->ifa_addr->sa_family; const int family = ifp->ifa_addr->sa_family;
if ((family == AF_INET || (ipv6_ && family == AF_INET6)) if ((family == AF_INET || (ipv6_ && family == AF_INET6))
&& !strcmp (nic_, ifp->ifa_name)) { && !strcmp (nic_, ifp->ifa_name)) {
if (is_src_) { if (is_src_)
memcpy (&source_address, ifp->ifa_addr, memcpy (&source_address, ifp->ifa_addr,
(family == AF_INET) ? sizeof (struct sockaddr_in) (family == AF_INET) ? sizeof (struct sockaddr_in)
: sizeof (struct sockaddr_in6)); : sizeof (struct sockaddr_in6));
} else { else
memcpy (&address, ifp->ifa_addr, memcpy (&address, ifp->ifa_addr,
(family == AF_INET) ? sizeof (struct sockaddr_in) (family == AF_INET) ? sizeof (struct sockaddr_in)
: sizeof (struct sockaddr_in6)); : sizeof (struct sockaddr_in6));
}
found = true; found = true;
break; break;
} }
...@@ -231,15 +227,15 @@ int zmq::tcp_address_t::resolve_interface (const char *interface_, bool ipv6_, b ...@@ -231,15 +227,15 @@ int zmq::tcp_address_t::resolve_interface (const char *interface_, bool ipv6_, b
// with the address. // with the address.
if (ipv6_) { if (ipv6_) {
sockaddr_in6 ip6_addr; sockaddr_in6 ip6_addr;
memset (&ip6_addr, 0, sizeof (ip6_addr)); memset (&ip6_addr, 0, sizeof ip6_addr);
ip6_addr.sin6_family = AF_INET6; ip6_addr.sin6_family = AF_INET6;
memcpy (&ip6_addr.sin6_addr, &in6addr_any, sizeof (in6addr_any)); memcpy (&ip6_addr.sin6_addr, &in6addr_any, sizeof in6addr_any);
out_addrlen = sizeof ip6_addr; out_addrlen = sizeof ip6_addr;
memcpy (out_addr, &ip6_addr, out_addrlen); memcpy (out_addr, &ip6_addr, out_addrlen);
} }
else { else {
sockaddr_in ip4_addr; sockaddr_in ip4_addr;
memset (&ip4_addr, 0, sizeof (ip4_addr)); memset (&ip4_addr, 0, sizeof ip4_addr);
ip4_addr.sin_family = AF_INET; ip4_addr.sin_family = AF_INET;
ip4_addr.sin_addr.s_addr = htonl (INADDR_ANY); ip4_addr.sin_addr.s_addr = htonl (INADDR_ANY);
out_addrlen = sizeof ip4_addr; out_addrlen = sizeof ip4_addr;
...@@ -248,20 +244,17 @@ int zmq::tcp_address_t::resolve_interface (const char *interface_, bool ipv6_, b ...@@ -248,20 +244,17 @@ int zmq::tcp_address_t::resolve_interface (const char *interface_, bool ipv6_, b
// "*" resolves to INADDR_ANY or in6addr_any. // "*" resolves to INADDR_ANY or in6addr_any.
if (strcmp (interface_, "*") == 0) { if (strcmp (interface_, "*") == 0) {
zmq_assert (out_addrlen <= sizeof address); zmq_assert (out_addrlen <= sizeof address);
if (is_src_) { if (is_src_)
memcpy (&source_address, out_addr, out_addrlen); memcpy (&source_address, out_addr, out_addrlen);
} else { else
memcpy (&address, out_addr, out_addrlen); memcpy (&address, out_addr, out_addrlen);
}
return 0; return 0;
} }
// Try to resolve the string as a NIC name. // Try to resolve the string as a NIC name.
int rc = resolve_nic_name (interface_, ipv6_, is_src_); int rc = resolve_nic_name (interface_, ipv6_, is_src_);
if (rc != 0 && errno != ENODEV) if (rc == 0 || errno != ENODEV)
return rc; return rc;
if (rc == 0)
return 0;
// There's no such interface name. Assume literal address. // There's no such interface name. Assume literal address.
#if defined ZMQ_HAVE_OPENVMS && defined __ia64 #if defined ZMQ_HAVE_OPENVMS && defined __ia64
...@@ -271,7 +264,7 @@ int zmq::tcp_address_t::resolve_interface (const char *interface_, bool ipv6_, b ...@@ -271,7 +264,7 @@ int zmq::tcp_address_t::resolve_interface (const char *interface_, bool ipv6_, b
addrinfo *res = NULL; addrinfo *res = NULL;
addrinfo req; addrinfo req;
#endif #endif
memset (&req, 0, sizeof (req)); memset (&req, 0, sizeof req);
// Choose IPv4 or IPv6 protocol family. Note that IPv6 allows for // Choose IPv4 or IPv6 protocol family. Note that IPv6 allows for
// IPv4-in-IPv6 addresses. // IPv4-in-IPv6 addresses.
...@@ -304,12 +297,11 @@ int zmq::tcp_address_t::resolve_interface (const char *interface_, bool ipv6_, b ...@@ -304,12 +297,11 @@ int zmq::tcp_address_t::resolve_interface (const char *interface_, bool ipv6_, b
// Use the first result. // Use the first result.
zmq_assert (res != NULL); zmq_assert (res != NULL);
zmq_assert ((size_t) (res->ai_addrlen) <= sizeof (address)); zmq_assert ((size_t) res->ai_addrlen <= sizeof address);
if (is_src_) { if (is_src_)
memcpy (&source_address, res->ai_addr, res->ai_addrlen); memcpy (&source_address, res->ai_addr, res->ai_addrlen);
} else { else
memcpy (&address, res->ai_addr, res->ai_addrlen); memcpy (&address, res->ai_addr, res->ai_addrlen);
}
// Cleanup getaddrinfo after copying the possibly referenced result. // Cleanup getaddrinfo after copying the possibly referenced result.
freeaddrinfo (res); freeaddrinfo (res);
...@@ -325,7 +317,7 @@ int zmq::tcp_address_t::resolve_hostname (const char *hostname_, bool ipv6_, boo ...@@ -325,7 +317,7 @@ int zmq::tcp_address_t::resolve_hostname (const char *hostname_, bool ipv6_, boo
#else #else
addrinfo req; addrinfo req;
#endif #endif
memset (&req, 0, sizeof (req)); memset (&req, 0, sizeof req);
// Choose IPv4 or IPv6 protocol family. Note that IPv6 allows for // Choose IPv4 or IPv6 protocol family. Note that IPv6 allows for
// IPv4-in-IPv6 addresses. // IPv4-in-IPv6 addresses.
...@@ -352,7 +344,7 @@ int zmq::tcp_address_t::resolve_hostname (const char *hostname_, bool ipv6_, boo ...@@ -352,7 +344,7 @@ int zmq::tcp_address_t::resolve_hostname (const char *hostname_, bool ipv6_, boo
#else #else
addrinfo *res; addrinfo *res;
#endif #endif
int rc = getaddrinfo (hostname_, NULL, &req, &res); const int rc = getaddrinfo (hostname_, NULL, &req, &res);
if (rc) { if (rc) {
switch (rc) { switch (rc) {
case EAI_MEMORY: case EAI_MEMORY:
...@@ -366,12 +358,11 @@ int zmq::tcp_address_t::resolve_hostname (const char *hostname_, bool ipv6_, boo ...@@ -366,12 +358,11 @@ int zmq::tcp_address_t::resolve_hostname (const char *hostname_, bool ipv6_, boo
} }
// Copy first result to output addr with hostname and service. // Copy first result to output addr with hostname and service.
zmq_assert ((size_t) (res->ai_addrlen) <= sizeof (address)); zmq_assert ((size_t) res->ai_addrlen <= sizeof address);
if (is_src_) { if (is_src_)
memcpy (&source_address, res->ai_addr, res->ai_addrlen); memcpy (&source_address, res->ai_addr, res->ai_addrlen);
} else { else
memcpy (&address, res->ai_addr, res->ai_addrlen); memcpy (&address, res->ai_addr, res->ai_addrlen);
}
freeaddrinfo (res); freeaddrinfo (res);
...@@ -381,22 +372,22 @@ int zmq::tcp_address_t::resolve_hostname (const char *hostname_, bool ipv6_, boo ...@@ -381,22 +372,22 @@ int zmq::tcp_address_t::resolve_hostname (const char *hostname_, bool ipv6_, boo
zmq::tcp_address_t::tcp_address_t () : zmq::tcp_address_t::tcp_address_t () :
_has_src_addr (false) _has_src_addr (false)
{ {
memset (&address, 0, sizeof (address)); memset (&address, 0, sizeof address);
memset (&source_address, 0, sizeof (source_address)); memset (&source_address, 0, sizeof source_address);
} }
zmq::tcp_address_t::tcp_address_t (const sockaddr *sa, socklen_t sa_len) : zmq::tcp_address_t::tcp_address_t (const sockaddr *sa, socklen_t sa_len) :
_has_src_addr (false) _has_src_addr (false)
{ {
zmq_assert(sa && sa_len > 0); zmq_assert (sa && sa_len > 0);
memset (&address, 0, sizeof (address)); memset (&address, 0, sizeof address);
memset (&source_address, 0, sizeof (source_address)); memset (&source_address, 0, sizeof source_address);
if (sa->sa_family == AF_INET && sa_len >= (socklen_t) sizeof (address.ipv4)) if (sa->sa_family == AF_INET && sa_len >= (socklen_t) sizeof address.ipv4)
memcpy(&address.ipv4, sa, sizeof (address.ipv4)); memcpy (&address.ipv4, sa, sizeof address.ipv4);
else else
if (sa->sa_family == AF_INET6 && sa_len >= (socklen_t) sizeof (address.ipv6)) if (sa->sa_family == AF_INET6 && sa_len >= (socklen_t) sizeof address.ipv6)
memcpy(&address.ipv6, sa, sizeof (address.ipv6)); memcpy (&address.ipv6, sa, sizeof address.ipv6);
} }
zmq::tcp_address_t::~tcp_address_t () zmq::tcp_address_t::~tcp_address_t ()
...@@ -410,7 +401,7 @@ int zmq::tcp_address_t::resolve (const char *name_, bool local_, bool ipv6_, boo ...@@ -410,7 +401,7 @@ int zmq::tcp_address_t::resolve (const char *name_, bool local_, bool ipv6_, boo
const char *src_delimiter = strrchr (name_, ';'); const char *src_delimiter = strrchr (name_, ';');
if (src_delimiter) { if (src_delimiter) {
std::string src_name (name_, src_delimiter - name_); std::string src_name (name_, src_delimiter - name_);
int rc = resolve(src_name.c_str(), local_, ipv6_, true); const int rc = resolve (src_name.c_str (), local_, ipv6_, true);
if (rc != 0) if (rc != 0)
return -1; return -1;
name_ = src_delimiter + 1; name_ = src_delimiter + 1;
...@@ -463,14 +454,14 @@ int zmq::tcp_address_t::resolve (const char *name_, bool local_, bool ipv6_, boo ...@@ -463,14 +454,14 @@ int zmq::tcp_address_t::resolve (const char *name_, bool local_, bool ipv6_, boo
source_address.ipv6.sin6_port = htons (port); source_address.ipv6.sin6_port = htons (port);
else else
source_address.ipv4.sin_port = htons (port); source_address.ipv4.sin_port = htons (port);
} else { }
else {
if (address.generic.sa_family == AF_INET6) if (address.generic.sa_family == AF_INET6)
address.ipv6.sin6_port = htons (port); address.ipv6.sin6_port = htons (port);
else else
address.ipv4.sin_port = htons (port); address.ipv4.sin_port = htons (port);
} }
return 0; return 0;
} }
...@@ -483,8 +474,8 @@ int zmq::tcp_address_t::to_string (std::string &addr_) ...@@ -483,8 +474,8 @@ int zmq::tcp_address_t::to_string (std::string &addr_)
} }
// not using service resolv because of https://github.com/zeromq/libzmq/commit/1824574f9b5a8ce786853320e3ea09fe1f822bc4 // not using service resolv because of https://github.com/zeromq/libzmq/commit/1824574f9b5a8ce786853320e3ea09fe1f822bc4
char hbuf[NI_MAXHOST]; char hbuf [NI_MAXHOST];
int rc = getnameinfo (addr (), addrlen (), hbuf, sizeof (hbuf), NULL, 0, NI_NUMERICHOST); int rc = getnameinfo (addr (), addrlen (), hbuf, sizeof hbuf, NULL, 0, NI_NUMERICHOST);
if (rc != 0) { if (rc != 0) {
addr_.clear (); addr_.clear ();
return rc; return rc;
...@@ -499,7 +490,7 @@ int zmq::tcp_address_t::to_string (std::string &addr_) ...@@ -499,7 +490,7 @@ int zmq::tcp_address_t::to_string (std::string &addr_)
std::stringstream s; std::stringstream s;
s << "tcp://" << hbuf << ":" << ntohs (address.ipv4.sin_port); s << "tcp://" << hbuf << ":" << ntohs (address.ipv4.sin_port);
addr_ = s.str (); addr_ = s.str ();
}; }
return 0; return 0;
} }
...@@ -511,9 +502,9 @@ const sockaddr *zmq::tcp_address_t::addr () const ...@@ -511,9 +502,9 @@ const sockaddr *zmq::tcp_address_t::addr () const
socklen_t zmq::tcp_address_t::addrlen () const socklen_t zmq::tcp_address_t::addrlen () const
{ {
if (address.generic.sa_family == AF_INET6) if (address.generic.sa_family == AF_INET6)
return (socklen_t) sizeof (address.ipv6); return (socklen_t) sizeof address.ipv6;
else else
return (socklen_t) sizeof (address.ipv4); return (socklen_t) sizeof address.ipv4;
} }
const sockaddr *zmq::tcp_address_t::src_addr () const const sockaddr *zmq::tcp_address_t::src_addr () const
...@@ -524,12 +515,12 @@ const sockaddr *zmq::tcp_address_t::src_addr () const ...@@ -524,12 +515,12 @@ const sockaddr *zmq::tcp_address_t::src_addr () const
socklen_t zmq::tcp_address_t::src_addrlen () const socklen_t zmq::tcp_address_t::src_addrlen () const
{ {
if (address.generic.sa_family == AF_INET6) if (address.generic.sa_family == AF_INET6)
return (socklen_t) sizeof (source_address.ipv6); return (socklen_t) sizeof source_address.ipv6;
else else
return (socklen_t) sizeof (source_address.ipv4); return (socklen_t) sizeof source_address.ipv4;
} }
bool zmq::tcp_address_t::has_src_addr() const bool zmq::tcp_address_t::has_src_addr () const
{ {
return _has_src_addr; return _has_src_addr;
} }
...@@ -544,9 +535,9 @@ sa_family_t zmq::tcp_address_t::family () const ...@@ -544,9 +535,9 @@ sa_family_t zmq::tcp_address_t::family () const
} }
zmq::tcp_address_mask_t::tcp_address_mask_t () : zmq::tcp_address_mask_t::tcp_address_mask_t () :
tcp_address_t () tcp_address_t (),
address_mask (-1)
{ {
address_mask = -1;
} }
int zmq::tcp_address_mask_t::mask () const int zmq::tcp_address_mask_t::mask () const
...@@ -572,7 +563,8 @@ int zmq::tcp_address_mask_t::resolve (const char *name_, bool ipv6_) ...@@ -572,7 +563,8 @@ int zmq::tcp_address_mask_t::resolve (const char *name_, bool ipv6_)
addr_str.assign (name_); addr_str.assign (name_);
// Parse address part using standard routines. // Parse address part using standard routines.
int rc = tcp_address_t::resolve_hostname (addr_str.c_str (), ipv6_); const int rc =
tcp_address_t::resolve_hostname (addr_str.c_str (), ipv6_);
if (rc != 0) if (rc != 0)
return rc; return rc;
...@@ -584,9 +576,8 @@ int zmq::tcp_address_mask_t::resolve (const char *name_, bool ipv6_) ...@@ -584,9 +576,8 @@ int zmq::tcp_address_mask_t::resolve (const char *name_, bool ipv6_)
address_mask = 32; address_mask = 32;
} }
else else
if (mask_str == "0") { if (mask_str == "0")
address_mask = 0; address_mask = 0;
}
else { else {
int mask = atoi (mask_str.c_str ()); int mask = atoi (mask_str.c_str ());
if ( if (
...@@ -605,7 +596,8 @@ int zmq::tcp_address_mask_t::resolve (const char *name_, bool ipv6_) ...@@ -605,7 +596,8 @@ int zmq::tcp_address_mask_t::resolve (const char *name_, bool ipv6_)
int zmq::tcp_address_mask_t::to_string (std::string &addr_) int zmq::tcp_address_mask_t::to_string (std::string &addr_)
{ {
if (address.generic.sa_family != AF_INET && address.generic.sa_family != AF_INET6) { if (address.generic.sa_family != AF_INET
&& address.generic.sa_family != AF_INET6) {
addr_.clear (); addr_.clear ();
return -1; return -1;
} }
...@@ -614,8 +606,8 @@ int zmq::tcp_address_mask_t::to_string (std::string &addr_) ...@@ -614,8 +606,8 @@ int zmq::tcp_address_mask_t::to_string (std::string &addr_)
return -1; return -1;
} }
char hbuf[NI_MAXHOST]; char hbuf [NI_MAXHOST];
int rc = getnameinfo (addr (), addrlen (), hbuf, sizeof (hbuf), NULL, 0, NI_NUMERICHOST); int rc = getnameinfo (addr (), addrlen (), hbuf, sizeof hbuf, NULL, 0, NI_NUMERICHOST);
if (rc != 0) { if (rc != 0) {
addr_.clear (); addr_.clear ();
return rc; return rc;
...@@ -630,13 +622,15 @@ int zmq::tcp_address_mask_t::to_string (std::string &addr_) ...@@ -630,13 +622,15 @@ int zmq::tcp_address_mask_t::to_string (std::string &addr_)
std::stringstream s; std::stringstream s;
s << hbuf << "/" << address_mask; s << hbuf << "/" << address_mask;
addr_ = s.str (); addr_ = s.str ();
}; }
return 0; return 0;
} }
bool zmq::tcp_address_mask_t::match_address (const struct sockaddr *ss, const socklen_t ss_len) const bool zmq::tcp_address_mask_t::match_address (const struct sockaddr *ss, const socklen_t ss_len) const
{ {
zmq_assert (address_mask != -1 && ss != NULL && ss_len >= (socklen_t) sizeof (struct sockaddr)); zmq_assert (address_mask != -1
&& ss != NULL
&& ss_len >= (socklen_t) sizeof (struct sockaddr));
if (ss->sa_family != address.generic.sa_family) if (ss->sa_family != address.generic.sa_family)
return false; return false;
...@@ -656,15 +650,16 @@ bool zmq::tcp_address_mask_t::match_address (const struct sockaddr *ss, const so ...@@ -656,15 +650,16 @@ bool zmq::tcp_address_mask_t::match_address (const struct sockaddr *ss, const so
our_bytes = (const uint8_t *) &address.ipv4.sin_addr; our_bytes = (const uint8_t *) &address.ipv4.sin_addr;
mask = sizeof (struct in_addr) * 8; mask = sizeof (struct in_addr) * 8;
} }
if (address_mask < mask) mask = address_mask; if (address_mask < mask)
mask = address_mask;
size_t full_bytes = mask / 8; const size_t full_bytes = mask / 8;
if (memcmp(our_bytes, their_bytes, full_bytes)) if (memcmp (our_bytes, their_bytes, full_bytes))
return false; return false;
uint8_t last_byte_bits = (0xffU << (8 - (mask % 8))) & 0xffU; const uint8_t last_byte_bits = (0xffU << (8 - (mask % 8))) & 0xffU;
if (last_byte_bits) { if (last_byte_bits) {
if ((their_bytes[full_bytes] & last_byte_bits) != (our_bytes[full_bytes] & last_byte_bits)) if ((their_bytes [full_bytes] & last_byte_bits) != (our_bytes [full_bytes] & last_byte_bits))
return false; return false;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment