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

@ -0,0 +1 @@
error: Bad IP address: not an IP

View file

@ -6,3 +6,4 @@ to_addr(10.20.30.40) = 10.20.30.40 (SUCCESS)
to_addr(100.200.30.40) = 100.200.30.40 (SUCCESS)
to_addr(10.0.0.0) = 10.0.0.0 (SUCCESS)
to_addr(10.00.00.000) = 10.0.0.0 (SUCCESS)
to_addr(not an IP) = :: (SUCCESS)

View file

@ -0,0 +1 @@
error: Bad string in SubNetVal ctor: 10.0.0.0

View file

@ -0,0 +1,3 @@
10.0.0.0/8, T
2607:f8b0::/32, T
::/0, T

View file

@ -1,5 +1,6 @@
# @TEST-EXEC: bro %INPUT >output
# @TEST-EXEC: bro -b %INPUT >output 2>error
# @TEST-EXEC: btest-diff output
# @TEST-EXEC: btest-diff error
function test_to_addr(ip: string, expect: addr)
{
@ -16,3 +17,4 @@ test_to_addr("10.20.30.40", 10.20.30.40);
test_to_addr("100.200.30.40", 100.200.30.40);
test_to_addr("10.0.0.0", 10.0.0.0);
test_to_addr("10.00.00.000", 10.0.0.0);
test_to_addr("not an IP", ::);

View file

@ -0,0 +1,11 @@
# @TEST-EXEC: bro -b %INPUT >output 2>error
# @TEST-EXEC: btest-diff output
# @TEST-EXEC: btest-diff error
global sn: subnet;
sn = to_subnet("10.0.0.0/8");
print sn, sn == 10.0.0.0/8;
sn = to_subnet("2607:f8b0::/32");
print sn, sn == 2607:f8b0::/32;
sn = to_subnet("10.0.0.0");
print sn, sn == ::/0;