libi2ncommon: (tomj) added always_mask flag to IP_RANGE::to_string
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Sun, 5 Sep 2004 18:26:29 +0000 (18:26 +0000)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Sun, 5 Sep 2004 18:26:29 +0000 (18:26 +0000)
src/ipfunc.cpp
src/ipfunc.hxx
test/ip_range.cpp

index a87e104..e2c7922 100644 (file)
@@ -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> IP_RANGE::to_cidr(void) const
@@ -277,8 +281,6 @@ vector<IP_RANGE> IP_RANGE::to_cidr(void) const
     return cidrs;
 }
 
-#include <iostream>
-
 vector<IP_RANGE> IP_RANGE::substract(const std::set<IP_RANGE> &to_substract) const
 {
     vector<IP_RANGE> rtn;
index 6e11b71..00f24bc 100644 (file)
@@ -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<IP_RANGE> to_cidr(void) const;
index 94f05c9..92e76a0 100644 (file)
@@ -832,14 +832,6 @@ class ip_range : public TestFixture
             vector<IP_RANGE> check_range;
             check_range.push_back("192.168.1.61");
             
-            vector<IP_RANGE>::const_iterator it, it_end = new_range.end();
-            for (it = new_range.begin(); it != it_end; it++) {
-                vector<IP_RANGE> cidrs = it->to_cidr();
-                vector<IP_RANGE>::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);
         }
 };