1 #include <stdio.h>
2 #include <string.h>
3 #include <netinet/in.h>
4
5
6 static int
do_test(void)7 do_test (void)
8 {
9 int result = 0;
10 char buf[16];
11 memset (buf, '\0', 16);
12
13 if (! IN6_IS_ADDR_UNSPECIFIED (buf))
14 {
15 puts ("positive IN6_IS_ADDR_UNSPECIFIED failed");
16 result = 1;
17 }
18 for (size_t i = 0; i < 16; ++i)
19 {
20 buf[i] = 1;
21 if (IN6_IS_ADDR_UNSPECIFIED (buf))
22 {
23 printf ("negative IN6_IS_ADDR_UNSPECIFIED with byte %zu failed\n",
24 i);
25 result = 1;
26 }
27 buf[i] = 0;
28 }
29
30 if (IN6_IS_ADDR_LOOPBACK (buf))
31 {
32 puts ("negative IN6_IS_ADDR_UNSPECIFIED failed");
33 result = 1;
34 }
35 buf[15] = 1;
36 if (! IN6_IS_ADDR_LOOPBACK (buf))
37 {
38 puts ("positive IN6_IS_ADDR_UNSPECIFIED failed");
39 result = 1;
40 }
41 buf[15] = 0;
42
43 buf[0] = 0xfe;
44 buf[1] = 0x80;
45 if (! IN6_IS_ADDR_LINKLOCAL (buf))
46 {
47 puts ("positive IN6_IS_ADDR_LINKLOCAL failed");
48 result = 1;
49 }
50 for (size_t i = 1; i < 16; ++i)
51 {
52 buf[i] ^= 1;
53 if (! IN6_IS_ADDR_LINKLOCAL (buf))
54 {
55 printf ("positive IN6_IS_ADDR_LINKLOCAL byte %zu failed\n", i);
56 result = 1;
57 }
58 buf[i] ^= 1;
59 }
60 buf[0] = 0xff;
61 buf[1] = 0x80;
62 if (IN6_IS_ADDR_LINKLOCAL (buf))
63 {
64 puts ("negative IN6_IS_ADDR_LINKLOCAL failed");
65 result = 1;
66 }
67 buf[0] = 0xfe;
68 buf[1] = 0xc0;
69 if (IN6_IS_ADDR_LINKLOCAL (buf))
70 {
71 puts ("negative IN6_IS_ADDR_LINKLOCAL #2 failed");
72 result = 1;
73 }
74
75 buf[0] = 0xfe;
76 buf[1] = 0xc0;
77 if (! IN6_IS_ADDR_SITELOCAL (buf))
78 {
79 puts ("positive IN6_IS_ADDR_SITELOCAL failed");
80 result = 1;
81 }
82 for (size_t i = 1; i < 16; ++i)
83 {
84 buf[i] ^= 1;
85 if (! IN6_IS_ADDR_SITELOCAL (buf))
86 {
87 printf ("positive IN6_IS_ADDR_SITELOCAL byte %zu failed\n", i);
88 result = 1;
89 }
90 buf[i] ^= 1;
91 }
92 buf[0] = 0xff;
93 buf[1] = 0x80;
94 if (IN6_IS_ADDR_SITELOCAL (buf))
95 {
96 puts ("negative IN6_IS_ADDR_SITELOCAL failed");
97 result = 1;
98 }
99 buf[0] = 0xf8;
100 buf[1] = 0xc0;
101 if (IN6_IS_ADDR_SITELOCAL (buf))
102 {
103 puts ("negative IN6_IS_ADDR_SITELOCAL #2 failed");
104 result = 1;
105 }
106
107 memset (buf, '\0', 16);
108 buf[10] = 0xff;
109 buf[11] = 0xff;
110 if (! IN6_IS_ADDR_V4MAPPED (buf))
111 {
112 puts ("positive IN6_IS_ADDR_V4MAPPED failed");
113 result = 1;
114 }
115 for (size_t i = 12; i < 16; ++i)
116 {
117 buf[i] ^= 1;
118 if (! IN6_IS_ADDR_V4MAPPED (buf))
119 {
120 printf ("positive IN6_IS_ADDR_V4MAPPED byte %zu failed\n", i);
121 result = 1;
122 }
123 buf[i] ^= 1;
124 }
125 for (size_t i = 0; i < 12; ++i)
126 {
127 buf[i] ^= 1;
128 if (IN6_IS_ADDR_V4MAPPED (buf))
129 {
130 printf ("negative IN6_IS_ADDR_V4MAPPED byte %zu failed\n", i);
131 result = 1;
132 }
133 buf[i] ^= 1;
134 }
135
136 memset (buf, '\0', 16);
137 for (size_t i = 12; i < 16; ++i)
138 {
139 buf[i] ^= 2;
140 if (! IN6_IS_ADDR_V4COMPAT (buf))
141 {
142 printf ("positive IN6_IS_ADDR_V4COMPAT byte %zu failed\n", i);
143 result = 1;
144 }
145 buf[i] ^= 2;
146 }
147 for (size_t i = 0; i < 12; ++i)
148 {
149 buf[i] ^= 1;
150 if (IN6_IS_ADDR_V4COMPAT (buf))
151 {
152 printf ("negative IN6_IS_ADDR_V4COMPAT byte %zu failed\n", i);
153 result = 1;
154 }
155 buf[i] ^= 1;
156 }
157 if (IN6_IS_ADDR_V4COMPAT (buf))
158 {
159 puts ("negative IN6_IS_ADDR_V4COMPAT #2 failed");
160 result = 1;
161 }
162 buf[15] = 1;
163 if (IN6_IS_ADDR_V4COMPAT (buf))
164 {
165 puts ("negative IN6_IS_ADDR_V4COMPAT #3 failed");
166 result = 1;
167 }
168
169 return result;
170 }
171
172 #include <support/test-driver.c>
173