Decrease strictness of parsing IPv4 strings into addrs. (fixes #775)

IPv4 strings in dotted-decimal format with decimal parts containing
leading zeroes now parse better.
This commit is contained in:
Jon Siwek 2012-02-20 14:28:42 -06:00
parent 1f7bfbb83c
commit b66b74e5dc
4 changed files with 72 additions and 1 deletions

View file

@ -0,0 +1,8 @@
to_addr(0.0.0.0) = 0.0.0.0 (SUCCESS)
to_addr(1.2.3.4) = 1.2.3.4 (SUCCESS)
to_addr(01.02.03.04) = 1.2.3.4 (SUCCESS)
to_addr(001.002.003.004) = 1.2.3.4 (SUCCESS)
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)

View file

@ -0,0 +1,18 @@
# @TEST-EXEC: bro %INPUT >output
# @TEST-EXEC: btest-diff output
function test_to_addr(ip: string, expect: addr)
{
local result = to_addr(ip);
print fmt("to_addr(%s) = %s (%s)", ip, result,
result == expect ? "SUCCESS" : "FAILURE");
}
test_to_addr("0.0.0.0", 0.0.0.0);
test_to_addr("1.2.3.4", 1.2.3.4);
test_to_addr("01.02.03.04", 1.2.3.4);
test_to_addr("001.002.003.004", 1.2.3.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);