diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-10-27 17:59:17 -0700 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-10-27 17:59:17 -0700 |
| commit | 88b100e5d0db5df16622fa48899cf652e09b3e91 (patch) | |
| tree | 175fd6bd5b52d8c7edc0d1b706dca281e7785702 /node/InetAddress.hpp | |
| parent | 51fcc753549e4f7c18efb889a841c4dd4fb9e6cf (diff) | |
| download | infinitytier-88b100e5d0db5df16622fa48899cf652e09b3e91.tar.gz infinitytier-88b100e5d0db5df16622fa48899cf652e09b3e91.zip | |
More cleanup.
Diffstat (limited to 'node/InetAddress.hpp')
| -rw-r--r-- | node/InetAddress.hpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/node/InetAddress.hpp b/node/InetAddress.hpp index ecafcf51..fcbed4b1 100644 --- a/node/InetAddress.hpp +++ b/node/InetAddress.hpp @@ -346,14 +346,19 @@ struct InetAddress : public sockaddr_storage } /** + * Performs an IP-only comparison or, if that is impossible, a memcmp() + * * @param a InetAddress to compare again * @return True if only IP portions are equal (false for non-IP or null addresses) */ inline bool ipsEqual(const InetAddress &a) const { - switch(ss_family) { - case AF_INET: return (reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr == reinterpret_cast<const struct sockaddr_in *>(&a)->sin_addr.s_addr); - case AF_INET6: return (memcmp(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr,reinterpret_cast<const struct sockaddr_in6 *>(&a)->sin6_addr.s6_addr,16) == 0); + if (ss_family == a.ss_family) { + if (ss_family == AF_INET) + return (reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr == reinterpret_cast<const struct sockaddr_in *>(&a)->sin_addr.s_addr); + if (ss_family == AF_INET6) + return (memcmp(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr,reinterpret_cast<const struct sockaddr_in6 *>(&a)->sin6_addr.s6_addr,16) == 0); + return (memcmp(this,&a,sizeof(InetAddress)) == 0); } return false; } |
