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;
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)
{
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;
}
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;