(WINT_MAX): Define as 2147483647 since this is the maximum UCS4 value.
[glibc/history.git] / inet / tst-inet6_rth.c
blob4c5c90ac013160b4f98b2924e0275a49cc190bfa
1 #include <stdio.h>
2 #include <string.h>
3 #include <arpa/inet.h>
4 #include <netinet/ip6.h>
6 static int
7 do_test (void)
9 int res = 0;
10 char buf[1000];
11 void *p = inet6_rth_init (buf, 24, IPV6_RTHDR_TYPE_0, 0);
12 if (p == NULL)
14 puts ("first inet6_rth_init failed");
15 res = 1;
17 else if (inet6_rth_add (p, &in6addr_any) == 0)
19 puts ("first inet6_rth_add succeeded");
20 res = 1;
23 p = inet6_rth_init (buf, 24, IPV6_RTHDR_TYPE_0, 1);
24 if (p == NULL)
26 puts ("second inet6_rth_init failed");
27 res = 1;
29 else if (inet6_rth_add (p, &in6addr_any) != 0)
31 puts ("second inet6_rth_add failed");
32 res = 1;
35 for (int nseg = 4; nseg < 6; ++nseg)
37 printf ("nseg = %d\n", nseg);
39 p = inet6_rth_init (buf, sizeof (buf), IPV6_RTHDR_TYPE_0, nseg);
40 if (p == NULL)
42 puts ("third inet6_rth_init failed");
43 res = 1;
45 else
47 struct in6_addr tmp;
48 memset (&tmp, '\0', sizeof (tmp));
50 for (int i = 0; i < nseg; ++i)
52 tmp.s6_addr[0] = i;
53 if (inet6_rth_add (p, &tmp) != 0)
55 printf ("call %d of third inet6_rth_add failed\n", i + 1);
56 res = 1;
57 goto out;
60 ((struct ip6_rthdr0 *) p)->ip6r0_segleft = 0;
61 if (inet6_rth_segments (p) != nseg)
63 puts ("\
64 inet6_rth_segments returned wrong value after loop with third inet6_rth_add");
65 res = 1;
66 goto out;
69 char buf2[1000];
70 if (inet6_rth_reverse (p, buf2) != 0)
72 puts ("first inet6_rth_reverse call failed");
73 res = 1;
74 goto out;
76 if (((struct ip6_rthdr0 *) buf2)->ip6r0_segleft != nseg)
78 puts ("segleft after first inet6_rth_reverse wrong");
79 res = 1;
82 if (inet6_rth_segments (p) != inet6_rth_segments (buf2))
84 puts ("number of seconds after first inet6_rth_reverse differs");
85 res = 1;
86 goto out;
89 for (int i = 0; i < nseg; ++i)
91 struct in6_addr *addr = inet6_rth_getaddr (buf2, i);
92 if (addr == NULL)
94 printf ("call %d of first inet6_rth_getaddr failed\n",
95 i + 1);
96 res = 1;
98 else if (addr->s6_addr[0] != nseg - 1 - i
99 || memcmp (&addr->s6_addr[1], &in6addr_any.s6_addr[1],
100 sizeof (in6addr_any)
101 - sizeof (in6addr_any.s6_addr[0])) != 0)
103 char addrbuf[100];
104 inet_ntop (AF_INET6, addr, addrbuf, sizeof (addrbuf));
105 printf ("\
106 address %d after first inet6_rth_reverse wrong (%s)\n",
107 i + 1, addrbuf);
108 res = 1;
111 out:
115 p = inet6_rth_init (buf, sizeof (buf), IPV6_RTHDR_TYPE_0, nseg);
116 if (p == NULL)
118 puts ("fourth inet6_rth_init failed");
119 res = 1;
121 else
123 struct in6_addr tmp;
124 memset (&tmp, '\0', sizeof (tmp));
126 for (int i = 0; i < nseg; ++i)
128 tmp.s6_addr[0] = i;
129 if (inet6_rth_add (p, &tmp) != 0)
131 printf ("call %d of fourth inet6_rth_add failed\n", i + 1);
132 res = 1;
133 goto out2;
136 ((struct ip6_rthdr0 *) p)->ip6r0_segleft = 0;
137 if (inet6_rth_segments (p) != nseg)
139 puts ("\
140 inet6_rth_segments returned wrong value after loop with fourth inet6_rth_add");
141 res = 1;
142 goto out2;
145 if (inet6_rth_reverse (p, p) != 0)
147 puts ("second inet6_rth_reverse call failed");
148 res = 1;
149 goto out2;
151 if (((struct ip6_rthdr0 *) p)->ip6r0_segleft != nseg)
153 puts ("segleft after second inet6_rth_reverse wrong");
154 res = 1;
157 for (int i = 0; i < nseg; ++i)
159 struct in6_addr *addr = inet6_rth_getaddr (p, i);
160 if (addr == NULL)
162 printf ("call %d of second inet6_rth_getaddr failed\n",
163 i + 1);
164 res = 1;
166 else if (addr->s6_addr[0] != nseg - 1 - i
167 || memcmp (&addr->s6_addr[1], &in6addr_any.s6_addr[1],
168 sizeof (in6addr_any)
169 - sizeof (in6addr_any.s6_addr[0])) != 0)
171 char addrbuf[100];
172 inet_ntop (AF_INET6, addr, addrbuf, sizeof (addrbuf));
173 printf ("\
174 address %d after second inet6_rth_reverse wrong (%s)\n",
175 i + 1, addrbuf);
176 res = 1;
179 out2:
184 return res;
187 #define TEST_FUNCTION do_test ()
188 #include "../test-skeleton.c"