diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2016-01-11 14:30:24 -0800 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2016-01-11 14:30:24 -0800 |
| commit | ba9fcb31d06e31f4b31a114093aee93054eb931a (patch) | |
| tree | dbc36d5a3a3f2442dc6dcb9e26500f5c0bf825b1 /node/InetAddress.cpp | |
| parent | 78c0f0a443919d8f214486f188c6e83a8af15fef (diff) | |
| parent | b3e3d4cacca37a4850e4e1a91fb8c42a5b13cb26 (diff) | |
| download | infinitytier-ba9fcb31d06e31f4b31a114093aee93054eb931a.tar.gz infinitytier-ba9fcb31d06e31f4b31a114093aee93054eb931a.zip | |
Merge branch 'dev' into edge
Diffstat (limited to 'node/InetAddress.cpp')
| -rw-r--r-- | node/InetAddress.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/node/InetAddress.cpp b/node/InetAddress.cpp index f35eb9c3..1b3a8064 100644 --- a/node/InetAddress.cpp +++ b/node/InetAddress.cpp @@ -280,6 +280,30 @@ InetAddress InetAddress::network() const return r; } +bool InetAddress::containsAddress(const InetAddress &addr) const +{ + if (addr.ss_family == ss_family) { + switch(ss_family) { + case AF_INET: { + const unsigned int bits = netmaskBits(); + return ( (Utils::ntoh((uint32_t)reinterpret_cast<const struct sockaddr_in *>(&addr)->sin_addr.s_addr) >> (32 - bits)) == (Utils::ntoh((uint32_t)reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr) >> (32 - bits)) ); + } + case AF_INET6: { + const InetAddress mask(netmask()); + const uint8_t *m = reinterpret_cast<const uint8_t *>(reinterpret_cast<const struct sockaddr_in6 *>(&mask)->sin6_addr.s6_addr); + const uint8_t *a = reinterpret_cast<const uint8_t *>(reinterpret_cast<const struct sockaddr_in6 *>(&addr)->sin6_addr.s6_addr); + const uint8_t *b = reinterpret_cast<const uint8_t *>(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr); + for(unsigned int i=0;i<16;++i) { + if ((a[i] & m[i]) != b[i]) + return false; + } + return true; + } + } + } + return false; +} + bool InetAddress::isNetwork() const throw() { |
