From dbee1b38b3fce2cab93c46157b9144bfab73cf87 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Mon, 29 Jun 2015 10:21:28 -0700 Subject: Fix semantics of std::unique() to actually remove duplicates (hidden memory leak?) --- node/InetAddress.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'node/InetAddress.cpp') diff --git a/node/InetAddress.cpp b/node/InetAddress.cpp index 940a58b2..83de36d4 100644 --- a/node/InetAddress.cpp +++ b/node/InetAddress.cpp @@ -273,6 +273,39 @@ InetAddress InetAddress::broadcast() const return r; } +bool InetAddress::isNetwork() const + throw() +{ + switch(ss_family) { + case AF_INET: { + unsigned int bits = netmaskBits(); + if (bits <= 0) + return false; + if (bits >= 32) + return false; + uint32_t ip = Utils::ntoh((uint32_t)reinterpret_cast(this)->sin_addr.s_addr); + return ((ip & (0xffffffff >> bits)) == 0); + } + case AF_INET6: { + unsigned int bits = netmaskBits(); + if (bits <= 0) + return false; + if (bits >= 128) + return false; + const unsigned char *ip = reinterpret_cast(reinterpret_cast(this)->sin6_addr.s6_addr); + unsigned int p = bits / 8; + if ((ip[p++] & (0xff >> (bits % 8))) != 0) + return false; + while (p < 16) { + if (ip[p++]) + return false; + } + return true; + } + } + return false; +} + bool InetAddress::operator==(const InetAddress &a) const throw() { -- cgit v1.2.3