]>
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.9 2001-05-09 02:47:26 itojun 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_ALTCOA 0x4
68 #define IP6SOPT_ALTCOA_MINLEN 18
69 #define IP6SOPT_UI 0x2
70 #define IP6SOPT_UI_MINLEN 4
72 static void ip6_sopt_print(const u_char
*, int);
75 ip6_sopt_print(const u_char
*bp
, int len
)
80 for (i
= 0; i
< len
; i
+= optlen
) {
81 if (bp
[i
] == IP6OPT_PAD1
)
85 optlen
= bp
[i
+ 1] + 2;
97 if (len
- i
< IP6OPT_MINLEN
) {
98 printf(", padn: trunc");
104 if (len
- i
< IP6SOPT_ALTCOA_MINLEN
) {
105 printf(", altcoa: trunc");
108 printf(", alt-CoA: %s", ip6addr_string(&bp
[i
+2]));
111 if (len
- i
< IP6SOPT_UI_MINLEN
) {
112 printf(", ui: trunc");
115 printf("(ui: 0x%04x) ", ntohs(*(u_int16_t
*)&bp
[i
+ 2]));
118 if (len
- i
< IP6OPT_MINLEN
) {
119 printf(", sopt_type %d: trunc)", bp
[i
]);
122 printf(", sopt_type 0x%02x: len=%d", bp
[i
], bp
[i
+ 1]);
133 ip6_opt_print(const u_char
*bp
, int len
)
138 for (i
= 0; i
< len
; i
+= optlen
) {
139 if (bp
[i
] == IP6OPT_PAD1
)
143 optlen
= bp
[i
+ 1] + 2;
147 if (i
+ optlen
> len
)
155 if (len
- i
< IP6OPT_MINLEN
) {
156 printf("(padn: trunc)");
161 case IP6OPT_ROUTER_ALERT
:
162 if (len
- i
< IP6OPT_RTALERT_LEN
) {
163 printf("(rtalert: trunc)");
166 if (bp
[i
+ 1] != IP6OPT_RTALERT_LEN
- 2) {
167 printf("(rtalert: invalid len %d)", bp
[i
+ 1]);
170 printf("(rtalert: 0x%04x) ", ntohs(*(u_int16_t
*)&bp
[i
+ 2]));
173 if (len
- i
< IP6OPT_JUMBO_LEN
) {
174 printf("(jumbo: trunc)");
177 if (bp
[i
+ 1] != IP6OPT_JUMBO_LEN
- 2) {
178 printf("(jumbo: invalid len %d)", bp
[i
+ 1]);
181 printf("(jumbo: %u) ", (u_int32_t
)ntohl(*(u_int32_t
*)&bp
[i
+ 2]));
183 case IP6OPT_HOME_ADDRESS
:
184 if (len
- i
< IP6OPT_HOMEADDR_MINLEN
) {
185 printf("(homeaddr: trunc)");
188 if (bp
[i
+ 1] < IP6OPT_HOMEADDR_MINLEN
- 2) {
189 printf("(homeaddr: invalid len %d)", bp
[i
+ 1]);
192 printf("(homeaddr: %s", ip6addr_string(&bp
[i
+ 2]));
193 if (bp
[i
+ 1] > IP6OPT_HOMEADDR_MINLEN
- 2) {
194 ip6_sopt_print(&bp
[i
+ IP6OPT_HOMEADDR_MINLEN
],
195 (optlen
- IP6OPT_HOMEADDR_MINLEN
));
199 case IP6OPT_BINDING_UPDATE
:
200 if (len
- i
< IP6OPT_BU_MINLEN
) {
201 printf("(bu: trunc)");
204 if (bp
[i
+ 1] < IP6OPT_BU_MINLEN
- 2) {
205 printf("(bu: invalid len %d)", bp
[i
+ 1]);
209 if (bp
[i
+ 2] & 0x80)
211 if (bp
[i
+ 2] & 0x40)
213 if (bp
[i
+ 2] & 0x20)
215 if (bp
[i
+ 2] & 0x10)
217 if (bp
[i
+ 2] & 0x0f)
219 printf(", prefixlen: %u", bp
[i
+ 3]);
220 printf(", sequence: %u",
221 (u_int16_t
)ntohs(*(u_int16_t
*)&bp
[i
+ 4]));
222 printf(", lifetime: %u",
223 (u_int32_t
)ntohs(*(u_int32_t
*)&bp
[i
+ 8]));
225 if (bp
[i
+ 1] > IP6OPT_BU_MINLEN
- 2) {
226 ip6_sopt_print(&bp
[i
+ IP6OPT_BU_MINLEN
],
227 (optlen
- IP6OPT_BU_MINLEN
));
231 case IP6OPT_BINDING_ACK
:
232 if (len
- i
< IP6OPT_BA_MINLEN
) {
233 printf("(ba: trunc)");
236 if (bp
[i
+ 1] < IP6OPT_BA_MINLEN
- 2) {
237 printf("(ba: invalid len %d)", bp
[i
+ 1]);
241 printf("status: %u", bp
[i
+ 2]);
242 printf(", sequence: %u",
243 (u_int16_t
)ntohs(*(u_int16_t
*)&bp
[i
+ 3]));
244 printf(", lifetime: %u",
245 (u_int32_t
)ntohs(*(u_int32_t
*)&bp
[i
+ 7]));
246 printf(", refresh: %u",
247 (u_int32_t
)ntohs(*(u_int32_t
*)&bp
[i
+ 11]));
249 if (bp
[i
+ 1] > IP6OPT_BA_MINLEN
- 2) {
250 ip6_sopt_print(&bp
[i
+ IP6OPT_BA_MINLEN
],
251 (optlen
- IP6OPT_BA_MINLEN
));
255 case IP6OPT_BINDING_REQ
:
256 if (len
- i
< IP6OPT_BR_MINLEN
) {
257 printf("(br: trunc)");
261 if (bp
[i
+ 1] > IP6OPT_BR_MINLEN
- 2) {
262 ip6_sopt_print(&bp
[i
+ IP6OPT_BR_MINLEN
],
263 (optlen
- IP6OPT_BR_MINLEN
));
268 if (len
- i
< IP6OPT_MINLEN
) {
269 printf("(type %d: trunc)", bp
[i
]);
272 printf("(opt_type 0x%02x: len=%d) ", bp
[i
], bp
[i
+ 1]);
287 hbhopt_print(register const u_char
*bp
)
289 const struct ip6_hbh
*dp
= (struct ip6_hbh
*)bp
;
290 register const u_char
*ep
;
293 /* 'ep' points to the end of available data. */
295 TCHECK(dp
->ip6h_len
);
296 hbhlen
= (int)((dp
->ip6h_len
+ 1) << 3);
297 TCHECK2(*dp
, hbhlen
);
300 ip6_opt_print((const u_char
*)dp
+ sizeof(*dp
), hbhlen
- sizeof(*dp
));
305 fputs("[|HBH]", stdout
);
310 dstopt_print(register const u_char
*bp
)
312 const struct ip6_dest
*dp
= (struct ip6_dest
*)bp
;
313 register const u_char
*ep
;
316 /* 'ep' points to the end of available data. */
318 TCHECK(dp
->ip6d_len
);
319 dstoptlen
= (int)((dp
->ip6d_len
+ 1) << 3);
320 TCHECK2(*dp
, dstoptlen
);
323 ip6_opt_print((const u_char
*)dp
+ sizeof(*dp
),
324 dstoptlen
- sizeof(*dp
));
330 fputs("[|DSTOPT]", stdout
);