From d9ed3132f3d25de3bdd5c2aef973d44d869d9395 Mon Sep 17 00:00:00 2001 From: Gerd v. Egidy Date: Sun, 29 Aug 2004 19:48:28 +0000 Subject: [PATCH] libi2ncommon: (gerd) add ip comparators --- src/ipfunc.cpp | 12 ++++++++++++ src/ipfunc.hxx | 4 +++- 2 files changed, 15 insertions(+), 1 deletions(-) diff --git a/src/ipfunc.cpp b/src/ipfunc.cpp index 9783249..1acee8c 100644 --- a/src/ipfunc.cpp +++ b/src/ipfunc.cpp @@ -153,6 +153,18 @@ int IP_RANGE::operator-(const IP_RANGE &other) return turn_ip(ip)-turn_ip(other.ip); } +bool operator==(const IP_RANGE& a, const IP_RANGE& b) +{ + // == even if comparing ranges and nets possible + return (a.ip==b.ip && a.end==b.end); +} + +bool operator<(const IP_RANGE& a, const IP_RANGE& b) +{ + return ((IP_RANGE::turn_ip(a.ip) < IP_RANGE::turn_ip(b.ip)) || + ((a.ip==b.ip) && IP_RANGE::turn_ip(a.end) < IP_RANGE::turn_ip(b.end))); +} + std::string IP_RANGE::to_string(void) const { struct in_addr ia_ip; diff --git a/src/ipfunc.hxx b/src/ipfunc.hxx index e525bdb..16aa2ae 100644 --- a/src/ipfunc.hxx +++ b/src/ipfunc.hxx @@ -18,7 +18,9 @@ class IP_RANGE { friend IP_RANGE operator+(const IP_RANGE &base, const int &ips); - + friend bool operator==(const IP_RANGE& a, const IP_RANGE& b); + friend bool operator<(const IP_RANGE& a, const IP_RANGE& b); + private: unsigned int ip; unsigned int mask; -- 1.7.1