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");
70 if (inet6_rth_reverse (p
, buf2
) != 0)
72 puts ("first inet6_rth_reverse call failed");
76 if (((struct ip6_rthdr0
*) buf2
)->ip6r0_segleft
!= nseg
)
78 puts ("segleft after first inet6_rth_reverse wrong");
82 if (inet6_rth_segments (p
) != inet6_rth_segments (buf2
))
84 puts ("number of seconds after first inet6_rth_reverse differs");
89 for (int i
= 0; i
< nseg
; ++i
)
91 struct in6_addr
*addr
= inet6_rth_getaddr (buf2
, i
);
94 printf ("call %d of first inet6_rth_getaddr failed\n",
98 else if (addr
->s6_addr
[0] != nseg
- 1 - i
99 || memcmp (&addr
->s6_addr
[1], &in6addr_any
.s6_addr
[1],
101 - sizeof (in6addr_any
.s6_addr
[0])) != 0)
104 inet_ntop (AF_INET6
, addr
, addrbuf
, sizeof (addrbuf
));
106 address %d after first inet6_rth_reverse wrong (%s)\n",
115 p
= inet6_rth_init (buf
, sizeof (buf
), IPV6_RTHDR_TYPE_0
, nseg
);
118 puts ("fourth inet6_rth_init failed");
124 memset (&tmp
, '\0', sizeof (tmp
));
126 for (int i
= 0; i
< nseg
; ++i
)
129 if (inet6_rth_add (p
, &tmp
) != 0)
131 printf ("call %d of fourth inet6_rth_add failed\n", i
+ 1);
136 ((struct ip6_rthdr0
*) p
)->ip6r0_segleft
= 0;
137 if (inet6_rth_segments (p
) != nseg
)
140 inet6_rth_segments returned wrong value after loop with fourth inet6_rth_add");
145 if (inet6_rth_reverse (p
, p
) != 0)
147 puts ("second inet6_rth_reverse call failed");
151 if (((struct ip6_rthdr0
*) p
)->ip6r0_segleft
!= nseg
)
153 puts ("segleft after second inet6_rth_reverse wrong");
157 for (int i
= 0; i
< nseg
; ++i
)
159 struct in6_addr
*addr
= inet6_rth_getaddr (p
, i
);
162 printf ("call %d of second inet6_rth_getaddr failed\n",
166 else if (addr
->s6_addr
[0] != nseg
- 1 - i
167 || memcmp (&addr
->s6_addr
[1], &in6addr_any
.s6_addr
[1],
169 - sizeof (in6addr_any
.s6_addr
[0])) != 0)
172 inet_ntop (AF_INET6
, addr
, addrbuf
, sizeof (addrbuf
));
174 address %d after second inet6_rth_reverse wrong (%s)\n",
187 #define TEST_FUNCTION do_test ()
188 #include "../test-skeleton.c"