aboutsummaryrefslogtreecommitdiff
path: root/inet
diff options
context:
space:
mode:
Diffstat (limited to 'inet')
-rw-r--r--inet/Makefile6
-rw-r--r--inet/netinet/in.h72
-rw-r--r--inet/tst-checks.c173
3 files changed, 238 insertions, 13 deletions
diff --git a/inet/Makefile b/inet/Makefile
index 3798594..12d573f 100644
--- a/inet/Makefile
+++ b/inet/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1991-2006, 2007, 2009 Free Software Foundation, Inc.
+# Copyright (C) 1991-2006, 2007, 2009, 2011 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
@@ -53,7 +53,7 @@ aux := check_pf check_native ifreq
tests := htontest test_ifindex tst-ntoa tst-ether_aton tst-network \
tst-gethnm test-ifaddrs bug-if1 test-inet6_opt tst-ether_line \
- tst-getni1 tst-getni2 tst-inet6_rth
+ tst-getni1 tst-getni2 tst-inet6_rth tst-checks
include ../Rules
@@ -97,5 +97,5 @@ endif
ifeq (yes,$(build-static-nss))
otherlibs += $(nssobjdir)/libnss_files.a $(resolvobjdir)/libnss_dns.a \
- $(resolvobjdir)/libresolv.a
+ $(resolvobjdir)/libresolv.a
endif
diff --git a/inet/netinet/in.h b/inet/netinet/in.h
index 180227a..2c2c184 100644
--- a/inet/netinet/in.h
+++ b/inet/netinet/in.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2001, 2003, 2004, 2006, 2007, 2008
+/* Copyright (C) 1991-2001, 2003, 2004, 2006, 2007, 2008, 2011
Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -396,44 +396,96 @@ extern uint16_t htons (uint16_t __hostshort)
# endif
#endif
-#define IN6_IS_ADDR_UNSPECIFIED(a) \
+#ifdef __GNUC__
+# define IN6_IS_ADDR_UNSPECIFIED(a) \
+ (__extension__ \
+ ({ __const struct in6_addr *__a = (__const struct in6_addr *) (a); \
+ __a->s6_addr32[0] == 0 \
+ && __a->s6_addr32[1] == 0 \
+ && __a->s6_addr32[2] == 0 \
+ && __a->s6_addr32[3] == 0; }))
+
+# define IN6_IS_ADDR_LOOPBACK(a) \
+ (__extension__ \
+ ({ __const struct in6_addr *__a = (__const struct in6_addr *) (a); \
+ __a->s6_addr32[0] == 0 \
+ && __a->s6_addr32[1] == 0 \
+ && __a->s6_addr32[2] == 0 \
+ && __a->s6_addr32[3] == htonl (1); }))
+
+# define IN6_IS_ADDR_LINKLOCAL(a) \
+ (__extension__ \
+ ({ __const struct in6_addr *__a = (__const struct in6_addr *) (a); \
+ (__a->s6_addr32[0] & htonl (0xffc00000)) == htonl (0xfe800000); }))
+
+# define IN6_IS_ADDR_SITELOCAL(a) \
+ (__extension__ \
+ ({ __const struct in6_addr *__a = (__const struct in6_addr *) (a); \
+ (__a->s6_addr32[0] & htonl (0xffc00000)) == htonl (0xfec00000); }))
+
+# define IN6_IS_ADDR_V4MAPPED(a) \
+ (__extension__ \
+ ({ __const struct in6_addr *__a = (__const struct in6_addr *) (a); \
+ __a->s6_addr32[0] == 0 \
+ && __a->s6_addr32[1] == 0 \
+ && __a->s6_addr32[2] == htonl (0xffff); }))
+
+# define IN6_IS_ADDR_V4COMPAT(a) \
+ (__extension__ \
+ ({ __const struct in6_addr *__a = (__const struct in6_addr *) (a); \
+ __a->s6_addr32[0] == 0 \
+ && __a->s6_addr32[1] == 0 \
+ && __a->s6_addr32[2] == 0 \
+ && ntohl (__a->s6_addr32[3]) > 1; }))
+
+# define IN6_ARE_ADDR_EQUAL(a,b) \
+ (__extension__ \
+ ({ __const struct in6_addr *__a = (__const struct in6_addr *) (a); \
+ __const struct in6_addr *__b = (__const struct in6_addr *) (b); \
+ __a->s6_addr32[0] == __b->s6_addr32[0] \
+ && __a->s6_addr32[1] == __b->s6_addr32[1] \
+ && __a->s6_addr32[2] == __b->s6_addr32[2] \
+ && __a->s6_addr32[3] == __b->s6_addr32[3]; }))
+#else
+# define IN6_IS_ADDR_UNSPECIFIED(a) \
(((__const uint32_t *) (a))[0] == 0 \
&& ((__const uint32_t *) (a))[1] == 0 \
&& ((__const uint32_t *) (a))[2] == 0 \
&& ((__const uint32_t *) (a))[3] == 0)
-#define IN6_IS_ADDR_LOOPBACK(a) \
+# define IN6_IS_ADDR_LOOPBACK(a) \
(((__const uint32_t *) (a))[0] == 0 \
&& ((__const uint32_t *) (a))[1] == 0 \
&& ((__const uint32_t *) (a))[2] == 0 \
&& ((__const uint32_t *) (a))[3] == htonl (1))
-#define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
-
-#define IN6_IS_ADDR_LINKLOCAL(a) \
+# define IN6_IS_ADDR_LINKLOCAL(a) \
((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
== htonl (0xfe800000))
-#define IN6_IS_ADDR_SITELOCAL(a) \
+# define IN6_IS_ADDR_SITELOCAL(a) \
((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
== htonl (0xfec00000))
-#define IN6_IS_ADDR_V4MAPPED(a) \
+# define IN6_IS_ADDR_V4MAPPED(a) \
((((__const uint32_t *) (a))[0] == 0) \
&& (((__const uint32_t *) (a))[1] == 0) \
&& (((__const uint32_t *) (a))[2] == htonl (0xffff)))
-#define IN6_IS_ADDR_V4COMPAT(a) \
+# define IN6_IS_ADDR_V4COMPAT(a) \
((((__const uint32_t *) (a))[0] == 0) \
&& (((__const uint32_t *) (a))[1] == 0) \
&& (((__const uint32_t *) (a))[2] == 0) \
&& (ntohl (((__const uint32_t *) (a))[3]) > 1))
-#define IN6_ARE_ADDR_EQUAL(a,b) \
+# define IN6_ARE_ADDR_EQUAL(a,b) \
((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0]) \
&& (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1]) \
&& (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2]) \
&& (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
+#endif
+
+#define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
#if defined __USE_MISC || defined __USE_GNU
/* Bind socket to a privileged IP port. */
diff --git a/inet/tst-checks.c b/inet/tst-checks.c
new file mode 100644
index 0000000..5d97564
--- /dev/null
+++ b/inet/tst-checks.c
@@ -0,0 +1,173 @@
+#include <stdio.h>
+#include <string.h>
+#include <netinet/in.h>
+
+
+static int
+do_test (void)
+{
+ int result = 0;
+ char buf[16];
+ memset (buf, '\0', 16);
+
+ if (! IN6_IS_ADDR_UNSPECIFIED (buf))
+ {
+ puts ("positive IN6_IS_ADDR_UNSPECIFIED failed");
+ result = 1;
+ }
+ for (size_t i = 0; i < 16; ++i)
+ {
+ buf[i] = 1;
+ if (IN6_IS_ADDR_UNSPECIFIED (buf))
+ {
+ printf ("negative IN6_IS_ADDR_UNSPECIFIED with byte %zu failed\n",
+ i);
+ result = 1;
+ }
+ buf[i] = 0;
+ }
+
+ if (IN6_IS_ADDR_LOOPBACK (buf))
+ {
+ puts ("negative IN6_IS_ADDR_UNSPECIFIED failed");
+ result = 1;
+ }
+ buf[15] = 1;
+ if (! IN6_IS_ADDR_LOOPBACK (buf))
+ {
+ puts ("positive IN6_IS_ADDR_UNSPECIFIED failed");
+ result = 1;
+ }
+ buf[15] = 0;
+
+ buf[0] = 0xfe;
+ buf[1] = 0x80;
+ if (! IN6_IS_ADDR_LINKLOCAL (buf))
+ {
+ puts ("positive IN6_IS_ADDR_LINKLOCAL failed");
+ result = 1;
+ }
+ for (size_t i = 1; i < 16; ++i)
+ {
+ buf[i] ^= 1;
+ if (! IN6_IS_ADDR_LINKLOCAL (buf))
+ {
+ printf ("positive IN6_IS_ADDR_LINKLOCAL byte %zu failed\n", i);
+ result = 1;
+ }
+ buf[i] ^= 1;
+ }
+ buf[0] = 0xff;
+ buf[1] = 0x80;
+ if (IN6_IS_ADDR_LINKLOCAL (buf))
+ {
+ puts ("negative IN6_IS_ADDR_LINKLOCAL failed");
+ result = 1;
+ }
+ buf[0] = 0xfe;
+ buf[1] = 0xc0;
+ if (IN6_IS_ADDR_LINKLOCAL (buf))
+ {
+ puts ("negative IN6_IS_ADDR_LINKLOCAL #2 failed");
+ result = 1;
+ }
+
+ buf[0] = 0xfe;
+ buf[1] = 0xc0;
+ if (! IN6_IS_ADDR_SITELOCAL (buf))
+ {
+ puts ("positive IN6_IS_ADDR_SITELOCAL failed");
+ result = 1;
+ }
+ for (size_t i = 1; i < 16; ++i)
+ {
+ buf[i] ^= 1;
+ if (! IN6_IS_ADDR_SITELOCAL (buf))
+ {
+ printf ("positive IN6_IS_ADDR_SITELOCAL byte %zu failed\n", i);
+ result = 1;
+ }
+ buf[i] ^= 1;
+ }
+ buf[0] = 0xff;
+ buf[1] = 0x80;
+ if (IN6_IS_ADDR_SITELOCAL (buf))
+ {
+ puts ("negative IN6_IS_ADDR_SITELOCAL failed");
+ result = 1;
+ }
+ buf[0] = 0xf8;
+ buf[1] = 0xc0;
+ if (IN6_IS_ADDR_SITELOCAL (buf))
+ {
+ puts ("negative IN6_IS_ADDR_SITELOCAL #2 failed");
+ result = 1;
+ }
+
+ memset (buf, '\0', 16);
+ buf[10] = 0xff;
+ buf[11] = 0xff;
+ if (! IN6_IS_ADDR_V4MAPPED (buf))
+ {
+ puts ("positive IN6_IS_ADDR_V4MAPPED failed");
+ result = 1;
+ }
+ for (size_t i = 12; i < 16; ++i)
+ {
+ buf[i] ^= 1;
+ if (! IN6_IS_ADDR_V4MAPPED (buf))
+ {
+ printf ("positive IN6_IS_ADDR_V4MAPPED byte %zu failed\n", i);
+ result = 1;
+ }
+ buf[i] ^= 1;
+ }
+ for (size_t i = 0; i < 12; ++i)
+ {
+ buf[i] ^= 1;
+ if (IN6_IS_ADDR_V4MAPPED (buf))
+ {
+ printf ("negative IN6_IS_ADDR_V4MAPPED byte %zu failed\n", i);
+ result = 1;
+ }
+ buf[i] ^= 1;
+ }
+
+ memset (buf, '\0', 16);
+ for (size_t i = 12; i < 16; ++i)
+ {
+ buf[i] ^= 2;
+ if (! IN6_IS_ADDR_V4COMPAT (buf))
+ {
+ printf ("positive IN6_IS_ADDR_V4COMPAT byte %zu failed\n", i);
+ result = 1;
+ }
+ buf[i] ^= 2;
+ }
+ for (size_t i = 0; i < 12; ++i)
+ {
+ buf[i] ^= 1;
+ if (IN6_IS_ADDR_V4COMPAT (buf))
+ {
+ printf ("negative IN6_IS_ADDR_V4COMPAT byte %zu failed\n", i);
+ result = 1;
+ }
+ buf[i] ^= 1;
+ }
+ if (IN6_IS_ADDR_V4COMPAT (buf))
+ {
+ puts ("negative IN6_IS_ADDR_V4COMPAT #2 failed");
+ result = 1;
+ }
+ buf[15] = 1;
+ if (IN6_IS_ADDR_V4COMPAT (buf))
+ {
+ puts ("negative IN6_IS_ADDR_V4COMPAT #3 failed");
+ result = 1;
+ }
+
+ return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"