From: Alex Rousskov Date: Sun, 2 May 2010 01:20:05 +0000 (-0600) Subject: Added whole-object comparison method so that IpAddress objects can be X-Git-Tag: SQUID_3_2_0_1~93^2~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=607a7bd462ac432387d643695c37c0e5feee5789;p=thirdparty%2Fsquid.git Added whole-object comparison method so that IpAddress objects can be properly sorted and used as std::map index. Existing IpAddress comparison operators do not work well because they only compare IP addresses (and incorrectly compare "none" and/or "any" IP addresses). --- diff --git a/src/ip/IpAddress.cc b/src/ip/IpAddress.cc index 464ad2ba40..2591e02a42 100644 --- a/src/ip/IpAddress.cc +++ b/src/ip/IpAddress.cc @@ -879,6 +879,11 @@ int IpAddress::matchIPAddr(const IpAddress &rhs) const return 0; } +int IpAddress::compareWhole(const IpAddress &rhs) const +{ + return memcmp(this, &rhs, sizeof(*this)); +} + bool IpAddress::operator ==(const IpAddress &s) const { return (0 == matchIPAddr(s)); diff --git a/src/ip/IpAddress.h b/src/ip/IpAddress.h index acb74ab67d..8423b42864 100644 --- a/src/ip/IpAddress.h +++ b/src/ip/IpAddress.h @@ -326,6 +326,13 @@ public: */ int matchIPAddr(const IpAddress &rhs) const; + /** Compare taking IP, port, protocol, etc. into account. Returns an + integer less than, equal to, or greater than zero if the object + is found, respectively, to be less than, to match, or to be greater + than rhs. The exact ordering algorithm is not specified and may change. + */ + int compareWhole(const IpAddress &rhs) const; + /** * Get RFC 3493 addrinfo structure from the IpAddress data * for protocol-neutral socket operations.