[ipv6] Add inet6_aton()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2013-09-11 04:26:39 +01:00
parent 8dd180f165
commit a9fa0d5f2b
3 changed files with 141 additions and 5 deletions

View File

@@ -60,6 +60,37 @@ FILE_LICENCE ( GPL2_OR_LATER );
ok ( strcmp ( actual, expected ) == 0 ); \
} 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 */