zeek/testing/btest/bifs/to_addr.bro
Jon Siwek bf3f184a01 Change IPv6 literal constant syntax to require encasing square brackets
This is to avoid ambiguity between compressed hex notation and
module namespacing, both which use "::". E.g.: "aaaa::bbbb" could
be an identifier or an IPv6 address, but "[aaaa::bbbb]" is now
clearly the address.

Also added IPv6 mixed notation to allow an IPv4 dotted-decimal
address to be specified in the lower 32-bits.
2012-03-13 13:47:07 -05:00

20 lines
639 B
Text

# @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)
{
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);
test_to_addr("not an IP", [::]);