aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2014-05-21 17:51:31 +0100
committerMichael Brown <mcb30@ipxe.org>2014-05-21 17:53:02 +0100
commit3c7f5f9c4ca535dbd2f86996f71342e685d4ce50 (patch)
tree8652f404aaeeb60dbc9f64517199ac3712439c10 /src
parent6cdd3bb6567b6e2fafa18db82bfb2c7d2bce9ebb (diff)
downloadipxe-3c7f5f9c4ca535dbd2f86996f71342e685d4ce50.zip
ipxe-3c7f5f9c4ca535dbd2f86996f71342e685d4ce50.tar.gz
ipxe-3c7f5f9c4ca535dbd2f86996f71342e685d4ce50.tar.bz2
[ipv6] Fix definition of IN6_IS_ADDR_LINKLOCAL()
Fix an erroneous htonl() in the definition of IN6_IS_ADDR_LINKLOCAL(), and add self-tests for the IN6_IS_ADDR_xxx() family of macros. Reported-by: Marin Hannache <git@mareo.fr> Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src')
-rw-r--r--src/include/ipxe/in.h2
-rw-r--r--src/tests/ipv6_test.c38
2 files changed, 39 insertions, 1 deletions
diff --git a/src/include/ipxe/in.h b/src/include/ipxe/in.h
index 3603247..de96ca2 100644
--- a/src/include/ipxe/in.h
+++ b/src/include/ipxe/in.h
@@ -61,7 +61,7 @@ struct in6_addr {
#define IN6_IS_ADDR_LINKLOCAL( addr ) \
( ( *( ( const uint16_t * ) (addr) ) & htons ( 0xffc0 ) ) == \
- htonl ( 0xfe80 ) )
+ htons ( 0xfe80 ) )
/**
* IPv4 socket address
diff --git a/src/tests/ipv6_test.c b/src/tests/ipv6_test.c
index 4de310a..e16fc7c 100644
--- a/src/tests/ipv6_test.c
+++ b/src/tests/ipv6_test.c
@@ -37,6 +37,30 @@ FILE_LICENCE ( GPL2_OR_LATER );
/** Define inline IPv6 address */
#define IPV6(...) { __VA_ARGS__ }
+/** The unspecified IPv6 address */
+static const struct in6_addr sample_unspecified = {
+ .s6_addr = IPV6 ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ),
+};
+
+/** A sample link-local IPv6 address */
+static const struct in6_addr sample_link_local = {
+ .s6_addr = IPV6 ( 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x69, 0xff, 0xfe, 0x50, 0x58, 0x45 ),
+};
+
+/** A sample global IPv6 address */
+static const struct in6_addr sample_global = {
+ .s6_addr = IPV6 ( 0x20, 0x01, 0x0b, 0xa8, 0x00, 0x00, 0x01, 0xd4,
+ 0x00, 0x00, 0x00, 0x00, 0x69, 0x50, 0x58, 0x45 ),
+};
+
+/** A sample multicast IPv6 address */
+static const struct in6_addr sample_multicast = {
+ .s6_addr = IPV6 ( 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ),
+};
+
/**
* Report an inet6_ntoa() test result
*
@@ -97,6 +121,20 @@ FILE_LICENCE ( GPL2_OR_LATER );
*/
static void ipv6_test_exec ( void ) {
+ /* Address testing macros */
+ ok ( IN6_IS_ADDR_UNSPECIFIED ( &sample_unspecified ) );
+ ok ( ! IN6_IS_ADDR_UNSPECIFIED ( &sample_link_local ) );
+ ok ( ! IN6_IS_ADDR_UNSPECIFIED ( &sample_global ) );
+ ok ( ! IN6_IS_ADDR_UNSPECIFIED ( &sample_multicast ) );
+ ok ( ! IN6_IS_ADDR_MULTICAST ( &sample_unspecified ) );
+ ok ( ! IN6_IS_ADDR_MULTICAST ( &sample_link_local ) );
+ ok ( ! IN6_IS_ADDR_MULTICAST ( &sample_global ) );
+ ok ( IN6_IS_ADDR_MULTICAST ( &sample_multicast ) );
+ ok ( ! IN6_IS_ADDR_LINKLOCAL ( &sample_unspecified ) );
+ ok ( IN6_IS_ADDR_LINKLOCAL ( &sample_link_local ) );
+ ok ( ! IN6_IS_ADDR_LINKLOCAL ( &sample_global ) );
+ ok ( ! IN6_IS_ADDR_LINKLOCAL ( &sample_multicast ) );
+
/* inet6_ntoa() tests */
inet6_ntoa_ok ( IPV6 ( 0x20, 0x01, 0x0b, 0xa8, 0x00, 0x00, 0x01, 0xd4,
0x00, 0x00, 0x00, 0x00, 0x69, 0x50, 0x58, 0x45 ),