summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2016-09-28 13:45:25 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2016-09-28 13:45:25 -0700
commit01129d02b3863f92c0f94b29e9600153b743f967 (patch)
tree11b83237b535f2883fbc226ffdd15df3e0f8572d /node
parente1fbf7b34c0e9db6c6845238bc553fc470857fef (diff)
downloadinfinitytier-01129d02b3863f92c0f94b29e9600153b743f967.tar.gz
infinitytier-01129d02b3863f92c0f94b29e9600153b743f967.zip
hashCode() for InetAddress
Diffstat (limited to 'node')
-rw-r--r--node/InetAddress.hpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/node/InetAddress.hpp b/node/InetAddress.hpp
index 2cd4dbd3..6f070fbf 100644
--- a/node/InetAddress.hpp
+++ b/node/InetAddress.hpp
@@ -414,6 +414,25 @@ struct InetAddress : public sockaddr_storage
return false;
}
+ inline unsigned long hashCode() const
+ {
+ if (ss_family == AF_INET) {
+ return ((unsigned long)reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr + (unsigned long)reinterpret_cast<const struct sockaddr_in *>(this)->sin_port);
+ } else if (ss_family == AF_INET6) {
+ unsigned long tmp = reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_port;
+ const uint8_t *a = reinterpret_cast<const uint8_t *>(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr);
+ for(long i=0;i<16;++i)
+ reinterpret_cast<uint8_t *>(&tmp)[i % sizeof(tmp)] ^= a[i];
+ return tmp;
+ } else {
+ unsigned long tmp = reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_port;
+ const uint8_t *a = reinterpret_cast<const uint8_t *>(this);
+ for(long i=0;i<sizeof(InetAddress);++i)
+ reinterpret_cast<uint8_t *>(&tmp)[i % sizeof(tmp)] ^= a[i];
+ return tmp;
+ }
+ }
+
/**
* Set to null/zero
*/