diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2016-01-11 10:17:44 -0800 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2016-01-11 10:17:44 -0800 |
| commit | b3e3d4cacca37a4850e4e1a91fb8c42a5b13cb26 (patch) | |
| tree | 0fbeba94f3021f8d55ada20c5ed8d193f574d70f /node/InetAddress.cpp | |
| parent | ba2a89c760f9bfa4936f3cf89155aafd047af917 (diff) | |
| download | infinitytier-b3e3d4cacca37a4850e4e1a91fb8c42a5b13cb26.tar.gz infinitytier-b3e3d4cacca37a4850e4e1a91fb8c42a5b13cb26.zip | |
Instead of using binary packet comparison, add a callback to the API to explicitly check whether paths should be used. Check in with this callback (if present) when learning new paths or sending initial packets.
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() { |
