4 #include <netinet/ip6.h>
11 void *p
= inet6_rth_init (buf
, 24, IPV6_RTHDR_TYPE_0
, 0);
14 puts ("first inet6_rth_init failed");
17 else if (inet6_rth_add (p
, &in6addr_any
) == 0)
19 puts ("first inet6_rth_add succeeded");
23 p
= inet6_rth_init (buf
, 24, IPV6_RTHDR_TYPE_0
, 1);
26 puts ("second inet6_rth_init failed");
29 else if (inet6_rth_add (p
, &in6addr_any
) != 0)
31 puts ("second inet6_rth_add failed");
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
);
42 puts ("third inet6_rth_init failed");
48 memset (&tmp
, '\0', sizeof (tmp
));
50 for (int i
= 0; i
< nseg
; ++i
)
53 if (inet6_rth_add (p
, &tmp
) != 0)
55 printf ("call %d of third inet6_rth_add failed\n", i
+ 1);
60 ((struct ip6_rthdr0
*) p
)->ip6r0_segleft
= 0;
61 if (inet6_rth_segments (p
) != nseg
)
64 inet6_rth_segments returned wrong value after loop with third inet6_rth_add");
72 struct ip6_rthdr0 rthdr0
;
74 if (inet6_rth_reverse (p
, buf2
.buffer
) != 0)
76 puts ("first inet6_rth_reverse call failed");
80 if (buf2
.rthdr0
.ip6r0_segleft
!= nseg
)
82 puts ("segleft after first inet6_rth_reverse wrong");
86 if (inet6_rth_segments (p
) != inet6_rth_segments (buf2
.buffer
))
88 puts ("number of seconds after first inet6_rth_reverse differs");
93 for (int i
= 0; i
< nseg
; ++i
)
95 struct in6_addr
*addr
= inet6_rth_getaddr (buf2
.buffer
, i
);
98 printf ("call %d of first inet6_rth_getaddr failed\n",
102 else if (addr
->s6_addr
[0] != nseg
- 1 - i
103 || memcmp (&addr
->s6_addr
[1], &in6addr_any
.s6_addr
[1],
105 - sizeof (in6addr_any
.s6_addr
[0])) != 0)
108 inet_ntop (AF_INET6
, addr
, addrbuf
, sizeof (addrbuf
));
110 address %d after first inet6_rth_reverse wrong (%s)\n",
119 p
= inet6_rth_init (buf
, sizeof (buf
), IPV6_RTHDR_TYPE_0
, nseg
);
122 puts ("fourth inet6_rth_init failed");
128 memset (&tmp
, '\0', sizeof (tmp
));
130 for (int i
= 0; i
< nseg
; ++i
)
133 if (inet6_rth_add (p
, &tmp
) != 0)
135 printf ("call %d of fourth inet6_rth_add failed\n", i
+ 1);
140 ((struct ip6_rthdr0
*) p
)->ip6r0_segleft
= 0;
141 if (inet6_rth_segments (p
) != nseg
)
144 inet6_rth_segments returned wrong value after loop with fourth inet6_rth_add");
149 if (inet6_rth_reverse (p
, p
) != 0)
151 puts ("second inet6_rth_reverse call failed");
155 if (((struct ip6_rthdr0
*) p
)->ip6r0_segleft
!= nseg
)
157 puts ("segleft after second inet6_rth_reverse wrong");
161 for (int i
= 0; i
< nseg
; ++i
)
163 struct in6_addr
*addr
= inet6_rth_getaddr (p
, i
);
166 printf ("call %d of second inet6_rth_getaddr failed\n",
170 else if (addr
->s6_addr
[0] != nseg
- 1 - i
171 || memcmp (&addr
->s6_addr
[1], &in6addr_any
.s6_addr
[1],
173 - sizeof (in6addr_any
.s6_addr
[0])) != 0)
176 inet_ntop (AF_INET6
, addr
, addrbuf
, sizeof (addrbuf
));
178 address %d after second inet6_rth_reverse wrong (%s)\n",
191 #define TEST_FUNCTION do_test ()
192 #include "../test-skeleton.c"