summaryrefslogtreecommitdiff
path: root/node/InetAddress.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-06-29 10:21:28 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-06-29 10:21:28 -0700
commitdbee1b38b3fce2cab93c46157b9144bfab73cf87 (patch)
tree9b2097871c534acf11adedd963808c7190391f90 /node/InetAddress.cpp
parent3f71afd0fbb2d87a2c9288166299600da51470dc (diff)
downloadinfinitytier-dbee1b38b3fce2cab93c46157b9144bfab73cf87.tar.gz
infinitytier-dbee1b38b3fce2cab93c46157b9144bfab73cf87.zip
Fix semantics of std::unique() to actually remove duplicates (hidden memory leak?)
Diffstat (limited to 'node/InetAddress.cpp')
-rw-r--r--node/InetAddress.cpp33
1 files changed, 33 insertions, 0 deletions
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<const struct sockaddr_in *>(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<const unsigned char *>(reinterpret_cast<const struct sockaddr_in6 *>(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()
{