Add to_subnet bif (fixes #782).

Also fix IPAddr::Mask/ReverseMask not allowing argument of 0.

And clarified return value of to_addr bif when the input string
does not parse into a valid IP address.
This commit is contained in:
Jon Siwek 2012-02-24 12:34:29 -06:00
parent c84394d07f
commit 32aabe8432
9 changed files with 59 additions and 14 deletions

View file

@ -911,11 +911,18 @@ bool AddrVal::DoUnserialize(UnserialInfo* info)
SubNetVal::SubNetVal(const char* text) : Val(TYPE_SUBNET)
{
const char* sep = strchr(text, '/');
if ( ! sep )
Internal("separator missing in SubNetVal::SubNetVal");
val.subnet_val = new IPPrefix(text, atoi(sep+1));
string s(text);
size_t slash_loc = s.find('/');
if ( slash_loc == string::npos )
{
reporter->Error("Bad string in SubNetVal ctor: %s", text);
val.subnet_val = new IPPrefix();
}
else
{
val.subnet_val = new IPPrefix(s.substr(0, slash_loc),
atoi(s.substr(slash_loc + 1).c_str()));
}
}
SubNetVal::SubNetVal(const char* text, int width) : Val(TYPE_SUBNET)