From 2910669d76a0f94073fd4f2a4d8d39dd3d0cff2f Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Mon, 6 Sep 2004 18:47:53 +0000 Subject: [PATCH] generate, libi2ncommon: (tomj) fixed named netmask output (supports only cidr) --- src/ipfunc.cpp | 28 +++++++++++++++++++--------- src/ipfunc.hxx | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/ipfunc.cpp b/src/ipfunc.cpp index 2000a23..0830c9e 100644 --- a/src/ipfunc.cpp +++ b/src/ipfunc.cpp @@ -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; } diff --git a/src/ipfunc.hxx b/src/ipfunc.hxx index ac86322..567e92c 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(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 to_cidr(void) const; -- 1.7.1