From 758b5caf945bad08d59a5832aeecff7af504d5de Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 14 Apr 2015 14:52:23 -0700 Subject: [PATCH] Fix < logic. --- node/InetAddress.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/node/InetAddress.cpp b/node/InetAddress.cpp index 3727d4713..54fc763fe 100644 --- a/node/InetAddress.cpp +++ b/node/InetAddress.cpp @@ -301,23 +301,33 @@ bool InetAddress::operator==(const InetAddress &a) const bool InetAddress::operator<(const InetAddress &a) const throw() { - if (ss_family < a.ss_family) { + if (ss_family < a.ss_family) + return true; + else if (ss_family == a.ss_family) { switch(ss_family) { case AF_INET: if (reinterpret_cast(this)->sin_port < reinterpret_cast(&a)->sin_port) return true; - if (reinterpret_cast(this)->sin_addr.s_addr < reinterpret_cast(&a)->sin_addr.s_addr) - return true; + else if (reinterpret_cast(this)->sin_port == reinterpret_cast(&a)->sin_port) { + if (reinterpret_cast(this)->sin_addr.s_addr < reinterpret_cast(&a)->sin_addr.s_addr) + return true; + } break; case AF_INET6: if (reinterpret_cast(this)->sin6_port < reinterpret_cast(&a)->sin6_port) return true; - if (reinterpret_cast(this)->sin6_flowinfo < reinterpret_cast(&a)->sin6_flowinfo) - return true; - if (memcmp(reinterpret_cast(this)->sin6_addr.s6_addr,reinterpret_cast(&a)->sin6_addr.s6_addr,16) < 0) - return true; - if (reinterpret_cast(this)->sin6_scope_id < reinterpret_cast(&a)->sin6_scope_id) - return true; + else if (reinterpret_cast(this)->sin6_port == reinterpret_cast(&a)->sin6_port) { + if (reinterpret_cast(this)->sin6_flowinfo < reinterpret_cast(&a)->sin6_flowinfo) + return true; + else if (reinterpret_cast(this)->sin6_flowinfo == reinterpret_cast(&a)->sin6_flowinfo) { + if (memcmp(reinterpret_cast(this)->sin6_addr.s6_addr,reinterpret_cast(&a)->sin6_addr.s6_addr,16) < 0) + return true; + else if (memcmp(reinterpret_cast(this)->sin6_addr.s6_addr,reinterpret_cast(&a)->sin6_addr.s6_addr,16) == 0) { + if (reinterpret_cast(this)->sin6_scope_id < reinterpret_cast(&a)->sin6_scope_id) + return true; + } + } + } break; default: return (memcmp(this,&a,sizeof(InetAddress)) < 0);