diff options
author | Grant Limberg <glimberg@gmail.com> | 2015-06-30 19:23:23 -0700 |
---|---|---|
committer | Grant Limberg <glimberg@gmail.com> | 2015-06-30 19:23:23 -0700 |
commit | d853dbf2d88d4c7b0016e4416b7d046801e4f65a (patch) | |
tree | 6e6e859a3da842b6158f04a2b110d0ed735eb9e8 /node/InetAddress.cpp | |
parent | aee8e95d4961195b3251bcc8581677a8f0c0cdd8 (diff) | |
parent | 0cbbcf288455b8657134bf5be0861232daa6c7d9 (diff) | |
download | infinitytier-d853dbf2d88d4c7b0016e4416b7d046801e4f65a.tar.gz infinitytier-d853dbf2d88d4c7b0016e4416b7d046801e4f65a.zip |
Merge branch 'adamierymenko-dev' into android-jni
Diffstat (limited to 'node/InetAddress.cpp')
-rw-r--r-- | node/InetAddress.cpp | 33 |
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() { |