]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Added whole-object comparison method so that IpAddress objects can be
authorAlex Rousskov <rousskov@measurement-factory.com>
Sun, 2 May 2010 01:20:05 +0000 (19:20 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Sun, 2 May 2010 01:20:05 +0000 (19:20 -0600)
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).

src/ip/IpAddress.cc
src/ip/IpAddress.h

index 464ad2ba40c6b7000e9b777bfbc95e24b6a38bbc..2591e02a421b53f8e386e6fe77faee120c2d998e 100644 (file)
@@ -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));
index acb74ab67d80a5e55b6022cc3e1969b8c0147402..8423b42864b327e37f09b2abf52246b7e303a0e2 100644 (file)
@@ -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.