diff --git a/src/beast/beast/net/IPAddress.h b/src/beast/beast/net/IPAddress.h index a0e1af1d7e..b946eaf898 100644 --- a/src/beast/beast/net/IPAddress.h +++ b/src/beast/beast/net/IPAddress.h @@ -325,6 +325,18 @@ public: struct key_equal; + /** LessThanComparable functor that ignores the port. */ + struct LessWithoutPort + { + bool operator() (IPAddress const& lhs, IPAddress const& rhs) const; + }; + + /** EqualityComparable functor that ignores the port. */ + struct EqualWithoutPort + { + bool operator() (IPAddress const& lhs, IPAddress const& rhs) const; + }; + private: Type m_type; uint16 m_port; @@ -370,6 +382,18 @@ struct IPAddress::key_equal } }; +inline bool IPAddress::LessWithoutPort::operator() ( + IPAddress const& lhs, IPAddress const& rhs) const +{ + return lhs.withPort (0) < rhs.withPort (0); +} + +inline bool IPAddress::EqualWithoutPort::operator() ( + IPAddress const& lhs, IPAddress const& rhs) const +{ + return lhs.withPort (0) == rhs.withPort (0); +} + } //------------------------------------------------------------------------------ diff --git a/src/beast/beast/net/impl/IPAddress.cpp b/src/beast/beast/net/impl/IPAddress.cpp index 10701a11ff..5190759f5b 100644 --- a/src/beast/beast/net/impl/IPAddress.cpp +++ b/src/beast/beast/net/impl/IPAddress.cpp @@ -581,7 +581,12 @@ bool operator== (IPAddress const& lhs, IPAddress const& rhs) switch (lhs.type()) { case IPAddress::none: return true; - case IPAddress::ipv4: return lhs.v4() == rhs.v4(); + case IPAddress::ipv4: + if (lhs.v4() != rhs.v4()) + return false; + if (lhs.port() != rhs.port()) + return false; + return true; case IPAddress::ipv6: default: bassertfalse; @@ -598,7 +603,12 @@ bool operator< (IPAddress const& lhs, IPAddress const& rhs) switch (lhs.type()) { case IPAddress::none: return true; - case IPAddress::ipv4: return lhs.v4() < rhs.v4(); + case IPAddress::ipv4: + if (lhs.v4() < rhs.v4()) + return true; + if (lhs.v4() > rhs.v4()) + return false; + return lhs.port() < rhs.port(); case IPAddress::ipv6: default: bassertfalse;