generate, libi2ncommon: (tomj) fixed named netmask output (supports only cidr)
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 6 Sep 2004 18:47:53 +0000 (18:47 +0000)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 6 Sep 2004 18:47:53 +0000 (18:47 +0000)
src/ipfunc.cpp
src/ipfunc.hxx

index 2000a23..0830c9e 100644 (file)
@@ -219,7 +219,7 @@ unsigned int IP_RANGE::get_netmask() const
     return mask;
 }
 
-std::string IP_RANGE::to_string(bool always_mask) const
+std::string IP_RANGE::to_string(bool always_mask, bool cidr_only) const
 {
     struct in_addr ia_ip;
     static const int bufsize=16;
@@ -234,11 +234,17 @@ std::string IP_RANGE::to_string(bool always_mask) const
     
     if (t==NETWORK)
     {
-        ia_ip.s_addr=mask;    
-        if (!inet_ntop(AF_INET,&ia_ip,buffer,bufsize))
-            return "";
-            
-        output=output+"/"+buffer;
+        if (cidr_only) {
+            ostringstream out;
+            out << "/" << get_mask_bits();
+            output+=out.str();
+        } else {
+            ia_ip.s_addr=mask;    
+            if (!inet_ntop(AF_INET,&ia_ip,buffer,bufsize))
+                return "";
+                
+            output=output+"/"+buffer;
+        }
     }
     else if (t==RANGE)
     {
@@ -248,9 +254,13 @@ std::string IP_RANGE::to_string(bool always_mask) const
             
         output=output+"-"+buffer;
     }
-    else if (t==IP && always_mask)
-        output+="/32";
-
+    else if (t==IP && always_mask) {
+        if (cidr_only)
+            output+="/32";
+        else
+            output+="/255.255.255.255";
+    }
+        
     return output;    
 }
 
index ac86322..567e92c 100644 (file)
@@ -54,7 +54,7 @@ class IP_RANGE
         int operator-(const IP_RANGE &other);
         
         // returns the complete IP_RANGE
-        std::string to_string(bool always_mask=false) const;
+        std::string to_string(bool always_mask=false, bool cidr_only=false) const;
         
         // returns the complete range in cidr blocks        
         std::vector<IP_RANGE> to_cidr(void) const;