]>
The Tcpdump Group git mirrors - tcpdump/blob - print-ip6opts.c
2 * Copyright (C) 1998 WIDE Project.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 static const char rcsid
[] =
36 "@(#) $Header: /tcpdump/master/tcpdump/print-ip6opts.c,v 1.10 2002-03-28 10:02:35 guy Exp $";
40 #include <sys/param.h>
42 #include <sys/types.h>
43 #include <sys/socket.h>
45 #include <netinet/in.h>
50 #include "interface.h"
51 #include "addrtoname.h"
53 /* items outside of rfc2292bis */
55 #define IP6OPT_MINLEN 2
57 #ifndef IP6OPT_RTALERT_LEN
58 #define IP6OPT_RTALERT_LEN 4
60 #ifndef IP6OPT_JUMBO_LEN
61 #define IP6OPT_JUMBO_LEN 6
63 #define IP6OPT_HOMEADDR_MINLEN 18
64 #define IP6OPT_BU_MINLEN 10
65 #define IP6OPT_BA_MINLEN 13
66 #define IP6OPT_BR_MINLEN 2
67 #define IP6SOPT_UI 0x2
68 #define IP6SOPT_UI_MINLEN 4
69 #define IP6SOPT_ALTCOA 0x3
70 #define IP6SOPT_ALTCOA_MINLEN 18
71 #define IP6SOPT_AUTH 0x4
72 #define IP6SOPT_AUTH_MINLEN 6
74 static void ip6_sopt_print(const u_char
*, int);
77 ip6_sopt_print(const u_char
*bp
, int len
)
82 for (i
= 0; i
< len
; i
+= optlen
) {
83 if (bp
[i
] == IP6OPT_PAD1
)
87 optlen
= bp
[i
+ 1] + 2;
99 if (len
- i
< IP6OPT_MINLEN
) {
100 printf(", padn: trunc");
106 if (len
- i
< IP6SOPT_UI_MINLEN
) {
107 printf(", ui: trunc");
110 printf(", ui: 0x%04x ", ntohs(*(u_int16_t
*)&bp
[i
+ 2]));
113 if (len
- i
< IP6SOPT_ALTCOA_MINLEN
) {
114 printf(", altcoa: trunc");
117 printf(", alt-CoA: %s", ip6addr_string(&bp
[i
+2]));
120 if (len
- i
< IP6SOPT_AUTH_MINLEN
) {
121 printf(", auth: trunc");
124 printf(", auth spi: 0x%08x",
125 (u_int32_t
)ntohl(*(u_int32_t
*)&bp
[i
+ 2]));
128 if (len
- i
< IP6OPT_MINLEN
) {
129 printf(", sopt_type %d: trunc)", bp
[i
]);
132 printf(", sopt_type 0x%02x: len=%d", bp
[i
], bp
[i
+ 1]);
143 ip6_opt_print(const u_char
*bp
, int len
)
148 for (i
= 0; i
< len
; i
+= optlen
) {
149 if (bp
[i
] == IP6OPT_PAD1
)
153 optlen
= bp
[i
+ 1] + 2;
157 if (i
+ optlen
> len
)
165 if (len
- i
< IP6OPT_MINLEN
) {
166 printf("(padn: trunc)");
171 case IP6OPT_ROUTER_ALERT
:
172 if (len
- i
< IP6OPT_RTALERT_LEN
) {
173 printf("(rtalert: trunc)");
176 if (bp
[i
+ 1] != IP6OPT_RTALERT_LEN
- 2) {
177 printf("(rtalert: invalid len %d)", bp
[i
+ 1]);
180 printf("(rtalert: 0x%04x) ", ntohs(*(u_int16_t
*)&bp
[i
+ 2]));
183 if (len
- i
< IP6OPT_JUMBO_LEN
) {
184 printf("(jumbo: trunc)");
187 if (bp
[i
+ 1] != IP6OPT_JUMBO_LEN
- 2) {
188 printf("(jumbo: invalid len %d)", bp
[i
+ 1]);
191 printf("(jumbo: %u) ", (u_int32_t
)ntohl(*(u_int32_t
*)&bp
[i
+ 2]));
193 case IP6OPT_HOME_ADDRESS
:
194 if (len
- i
< IP6OPT_HOMEADDR_MINLEN
) {
195 printf("(homeaddr: trunc)");
198 if (bp
[i
+ 1] < IP6OPT_HOMEADDR_MINLEN
- 2) {
199 printf("(homeaddr: invalid len %d)", bp
[i
+ 1]);
202 printf("(homeaddr: %s", ip6addr_string(&bp
[i
+ 2]));
203 if (bp
[i
+ 1] > IP6OPT_HOMEADDR_MINLEN
- 2) {
204 ip6_sopt_print(&bp
[i
+ IP6OPT_HOMEADDR_MINLEN
],
205 (optlen
- IP6OPT_HOMEADDR_MINLEN
));
209 case IP6OPT_BINDING_UPDATE
:
210 if (len
- i
< IP6OPT_BU_MINLEN
) {
211 printf("(bu: trunc)");
214 if (bp
[i
+ 1] < IP6OPT_BU_MINLEN
- 2) {
215 printf("(bu: invalid len %d)", bp
[i
+ 1]);
219 if (bp
[i
+ 2] & 0x80)
221 if (bp
[i
+ 2] & 0x40)
223 if (bp
[i
+ 2] & 0x20)
225 if (bp
[i
+ 2] & 0x10)
227 if ((bp
[i
+ 2] & 0x0f) || bp
[i
+ 3] || bp
[i
+ 4])
229 printf(", sequence: %u", bp
[i
+ 5]);
230 printf(", lifetime: %u",
231 (u_int32_t
)ntohl(*(u_int32_t
*)&bp
[i
+ 6]));
233 if (bp
[i
+ 1] > IP6OPT_BU_MINLEN
- 2) {
234 ip6_sopt_print(&bp
[i
+ IP6OPT_BU_MINLEN
],
235 (optlen
- IP6OPT_BU_MINLEN
));
239 case IP6OPT_BINDING_ACK
:
240 if (len
- i
< IP6OPT_BA_MINLEN
) {
241 printf("(ba: trunc)");
244 if (bp
[i
+ 1] < IP6OPT_BA_MINLEN
- 2) {
245 printf("(ba: invalid len %d)", bp
[i
+ 1]);
249 printf("status: %u", bp
[i
+ 2]);
252 printf(", sequence: %u", bp
[i
+ 4]);
253 printf(", lifetime: %u",
254 (u_int32_t
)ntohl(*(u_int32_t
*)&bp
[i
+ 5]));
255 printf(", refresh: %u",
256 (u_int32_t
)ntohl(*(u_int32_t
*)&bp
[i
+ 9]));
258 if (bp
[i
+ 1] > IP6OPT_BA_MINLEN
- 2) {
259 ip6_sopt_print(&bp
[i
+ IP6OPT_BA_MINLEN
],
260 (optlen
- IP6OPT_BA_MINLEN
));
264 case IP6OPT_BINDING_REQ
:
265 if (len
- i
< IP6OPT_BR_MINLEN
) {
266 printf("(br: trunc)");
270 if (bp
[i
+ 1] > IP6OPT_BR_MINLEN
- 2) {
271 ip6_sopt_print(&bp
[i
+ IP6OPT_BR_MINLEN
],
272 (optlen
- IP6OPT_BR_MINLEN
));
277 if (len
- i
< IP6OPT_MINLEN
) {
278 printf("(type %d: trunc)", bp
[i
]);
281 printf("(opt_type 0x%02x: len=%d) ", bp
[i
], bp
[i
+ 1]);
296 hbhopt_print(register const u_char
*bp
)
298 const struct ip6_hbh
*dp
= (struct ip6_hbh
*)bp
;
299 register const u_char
*ep
;
302 /* 'ep' points to the end of available data. */
304 TCHECK(dp
->ip6h_len
);
305 hbhlen
= (int)((dp
->ip6h_len
+ 1) << 3);
306 TCHECK2(*dp
, hbhlen
);
309 ip6_opt_print((const u_char
*)dp
+ sizeof(*dp
), hbhlen
- sizeof(*dp
));
314 fputs("[|HBH]", stdout
);
319 dstopt_print(register const u_char
*bp
)
321 const struct ip6_dest
*dp
= (struct ip6_dest
*)bp
;
322 register const u_char
*ep
;
325 /* 'ep' points to the end of available data. */
327 TCHECK(dp
->ip6d_len
);
328 dstoptlen
= (int)((dp
->ip6d_len
+ 1) << 3);
329 TCHECK2(*dp
, dstoptlen
);
332 ip6_opt_print((const u_char
*)dp
+ sizeof(*dp
),
333 dstoptlen
- sizeof(*dp
));
339 fputs("[|DSTOPT]", stdout
);