diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-02-02 14:44:24 -0800 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-02-02 14:44:24 -0800 |
commit | c30bf7957eda4f857185f6d23255fbdd27d77764 (patch) | |
tree | bb0b872e0001c518c8d35c15b5ff8010642faf44 /node | |
parent | d73a11b60be13f763f57639c0a7e42beaceb381b (diff) | |
download | infinitytier-c30bf7957eda4f857185f6d23255fbdd27d77764.tar.gz infinitytier-c30bf7957eda4f857185f6d23255fbdd27d77764.zip |
Hash code method for InetAddress
Diffstat (limited to 'node')
-rw-r--r-- | node/InetAddress.hpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/node/InetAddress.hpp b/node/InetAddress.hpp index d22b1ca9..d934e4d4 100644 --- a/node/InetAddress.hpp +++ b/node/InetAddress.hpp @@ -271,6 +271,20 @@ public: } /** + * @return Checksum of this address (not portable, so don't use for long-term storage purposes) + */ + inline uint64_t hashCode() const + { + switch(_sa.saddr.sa_family) { + case AF_INET: + return ((uint64_t)_sa.sin.sin_port + (uint64_t)(_sa.sin.sin_addr.s_addr)); + case AF_INET6: + return ((uint64_t)_sa.sin6.sin6_port + ( ((const uint64_t *)_sa.sin6.sin6_addr.s6_addr)[0] ^ ((const uint64_t *)_sa.sin6.sin6_addr.s6_addr)[1] )); + } + return 0; + } + + /** * @return Combined length of internal structure, room for either V4 or V6 */ inline unsigned int saddrSpaceLen() const throw() { return sizeof(_sa); } |