diff options
author | Michael Brown | 2013-09-11 05:26:39 +0200 |
---|---|---|
committer | Michael Brown | 2013-09-11 12:27:13 +0200 |
commit | a9fa0d5f2bd5254464f63a7312857fcec83bf37f (patch) | |
tree | 53ff15f22819b38c29219ed1a76513040f07bd2d /src/tests/ipv6_test.c | |
parent | [tcp] Reduce path MTU to 1280 bytes (diff) | |
download | ipxe-a9fa0d5f2bd5254464f63a7312857fcec83bf37f.tar.gz ipxe-a9fa0d5f2bd5254464f63a7312857fcec83bf37f.tar.xz ipxe-a9fa0d5f2bd5254464f63a7312857fcec83bf37f.zip |
[ipv6] Add inet6_aton()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/tests/ipv6_test.c')
-rw-r--r-- | src/tests/ipv6_test.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/tests/ipv6_test.c b/src/tests/ipv6_test.c index 10e964d9..4de310ab 100644 --- a/src/tests/ipv6_test.c +++ b/src/tests/ipv6_test.c @@ -61,6 +61,37 @@ FILE_LICENCE ( GPL2_OR_LATER ); } while ( 0 ) /** + * Report an inet6_aton() test result + * + * @v text Textual representation + * @v addr Expected IPv6 address + */ +#define inet6_aton_ok( text, addr ) do { \ + static const char string[] = text; \ + static const struct in6_addr expected = { \ + .s6_addr = addr, \ + }; \ + struct in6_addr actual; \ + \ + ok ( inet6_aton ( string, &actual ) == 0 ); \ + DBG ( "inet6_aton ( \"%s\" ) = %s\n", string, \ + inet6_ntoa ( &actual ) ); \ + ok ( memcmp ( &actual, &expected, sizeof ( actual ) ) == 0 ); \ + } while ( 0 ) + +/** + * Report an inet6_aton() failure test result + * + * @v text Textual representation + */ +#define inet6_aton_fail_ok( text ) do { \ + static const char string[] = text; \ + struct in6_addr dummy; \ + \ + ok ( inet6_aton ( string, &dummy ) != 0 ); \ + } while ( 0 ) + +/** * Perform IPv6 self-tests * */ @@ -106,6 +137,41 @@ static void ipv6_test_exec ( void ) { inet6_ntoa_ok ( IPV6 ( 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ), "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" ); + + /* inet6_aton() tests */ + inet6_aton_ok ( "2001:ba8:0:1d4::6950:5845", + IPV6 ( 0x20, 0x01, 0x0b, 0xa8, 0x00, 0x00, 0x01, 0xd4, + 0x00, 0x00, 0x00, 0x00, 0x69, 0x50, 0x58, 0x45)); + /* No zeros */ + inet6_aton_ok ( "2001:db8:1:1:1:1:1:1", + IPV6 ( 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x01, 0x00, 0x01, + 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01)); + /* All intervening zeros */ + inet6_aton_ok ( "fe80::1", + IPV6 ( 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01)); + /* Trailing run of zeros */ + inet6_aton_ok ( "fe80::", + IPV6 ( 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)); + /* Leading run of zeros */ + inet6_aton_ok ( "::1", + IPV6 ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01)); + /* All zeros */ + inet6_aton_ok ( "::", + IPV6 ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)); + + /* inet6_aton() failure tests */ + inet6_aton_fail_ok ( "20012:ba8:0:1d4::6950:5845" ); + inet6_aton_fail_ok ( "200z:ba8:0:1d4::6950:5845" ); + inet6_aton_fail_ok ( "2001.ba8:0:1d4::6950:5845" ); + inet6_aton_fail_ok ( "2001:db8:1:1:1:1:1" ); + inet6_aton_fail_ok ( "2001:db8:1:1:1:1:1:1:2" ); + inet6_aton_fail_ok ( "2001:db8::1::2" ); + inet6_aton_fail_ok ( "2001:ba8:0:1d4:::6950:5845" ); + inet6_aton_fail_ok ( ":::" ); } /** IPv6 self-test */ |