mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
Hash code method for InetAddress
This commit is contained in:
parent
d73a11b60b
commit
c30bf7957e
1 changed files with 14 additions and 0 deletions
|
@ -270,6 +270,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
|
* @return Combined length of internal structure, room for either V4 or V6
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue