From 81fb41ce16d853dcf8bc3c6c433daa61a7cb029f Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Sun, 5 Sep 2004 18:26:29 +0000 Subject: [PATCH] libi2ncommon: (tomj) added always_mask flag to IP_RANGE::to_string --- src/ipfunc.cpp | 10 ++++++---- src/ipfunc.hxx | 2 +- test/ip_range.cpp | 8 -------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/ipfunc.cpp b/src/ipfunc.cpp index a87e104..e2c7922 100644 --- a/src/ipfunc.cpp +++ b/src/ipfunc.cpp @@ -211,7 +211,7 @@ bool operator<(const IP_RANGE& a, const IP_RANGE& b) ((a.ip==b.ip) && IP_RANGE::turn_ip(a.end) < IP_RANGE::turn_ip(b.end))); } -std::string IP_RANGE::to_string(void) const +std::string IP_RANGE::to_string(bool always_mask) const { struct in_addr ia_ip; static const int bufsize=16; @@ -241,7 +241,11 @@ std::string IP_RANGE::to_string(void) const output=output+"-"+buffer; } - return output; + // t == IP + if (always_mask) + return output+"/32"; + else + return output; } vector IP_RANGE::to_cidr(void) const @@ -277,8 +281,6 @@ vector IP_RANGE::to_cidr(void) const return cidrs; } -#include - vector IP_RANGE::substract(const std::set &to_substract) const { vector rtn; diff --git a/src/ipfunc.hxx b/src/ipfunc.hxx index 6e11b71..00f24bc 100644 --- a/src/ipfunc.hxx +++ b/src/ipfunc.hxx @@ -54,7 +54,7 @@ class IP_RANGE int operator-(const IP_RANGE &other); // returns the complete IP_RANGE - std::string to_string(void) const; + std::string to_string(bool always_mask=false) const; // returns the complete range in cidr blocks std::vector to_cidr(void) const; diff --git a/test/ip_range.cpp b/test/ip_range.cpp index 94f05c9..92e76a0 100644 --- a/test/ip_range.cpp +++ b/test/ip_range.cpp @@ -832,14 +832,6 @@ class ip_range : public TestFixture vector check_range; check_range.push_back("192.168.1.61"); - vector::const_iterator it, it_end = new_range.end(); - for (it = new_range.begin(); it != it_end; it++) { - vector cidrs = it->to_cidr(); - vector::const_iterator cidr, cidrs_end = cidrs.end(); - for (cidr = cidrs.begin(); cidr != cidrs_end; cidr++) - cerr << "Range as CIDR: " << cidr->to_string() << endl; - } - CPPUNIT_ASSERT_EQUAL(check_range,new_range); } }; -- 1.7.1