]>
The Tcpdump Group git mirrors - tcpdump/blob - print-ip6opts.c
a860e9615732e50a886ce39c651c3f0ec9a9c770
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.3 2000-01-09 21:34:18 fenner Exp $";
40 #include <sys/param.h>
42 #include <sys/types.h>
43 #include <sys/socket.h>
45 #include <netinet/in.h>
46 #include <netinet/ip6.h>
50 #include "interface.h"
51 #include "addrtoname.h"
54 ip6_opt_print(const u_char
*bp
, int len
)
59 for (i
= 0; i
< len
; i
+= optlen
) {
65 if (len
- i
< IP6OPT_MINLEN
) {
66 printf("(padn: trunc)");
69 optlen
= bp
[i
+ 1] + 2;
72 if (len
- i
< IP6OPT_RTALERT_LEN
) {
73 printf("(rtalert: trunc)");
76 if (bp
[i
+ 1] != IP6OPT_RTALERT_LEN
- 2) {
77 printf("(rtalert: invalid len %d)", bp
[i
+ 1]);
80 printf("(rtalert: 0x%04x) ", ntohs(*(u_short
*)&bp
[i
+ 2]));
81 optlen
= IP6OPT_RTALERT_LEN
;
84 if (len
- i
< IP6OPT_JUMBO_LEN
) {
85 printf("(jumbo: trunc)");
88 if (bp
[i
+ 1] != IP6OPT_JUMBO_LEN
- 2) {
89 printf("(jumbo: invalid len %d)", bp
[i
+ 1]);
92 printf("(jumbo: %u) ", (u_int32_t
)ntohl(*(u_int
*)&bp
[i
+ 2]));
93 optlen
= IP6OPT_JUMBO_LEN
;
96 if (len
- i
< IP6OPT_MINLEN
) {
97 printf("(type %d: trunc)", bp
[i
]);
100 printf("(type 0x%02x: len=%d) ", bp
[i
], bp
[i
+ 1]);
101 optlen
= bp
[i
+ 1] + 2;
116 hbhopt_print(register const u_char
*bp
)
118 const struct ip6_hbh
*dp
= (struct ip6_hbh
*)bp
;
119 register const u_char
*ep
;
122 /* 'ep' points to the end of avaible data. */
124 TCHECK(dp
->ip6h_len
);
125 hbhlen
= (int)((dp
->ip6h_len
+ 1) << 3);
129 ip6_opt_print((const u_char
*)dp
+ sizeof(*dp
), hbhlen
- sizeof(*dp
));
134 fputs("[|HBH]", stdout
);
139 dstopt_print(register const u_char
*bp
)
141 const struct ip6_dest
*dp
= (struct ip6_dest
*)bp
;
142 register const u_char
*ep
;
145 /* 'ep' points to the end of avaible data. */
147 TCHECK(dp
->ip6d_len
);
148 dstoptlen
= (int)((dp
->ip6d_len
+ 1) << 3);
149 TCHECK2(dp
, dstoptlen
);
152 ip6_opt_print((const u_char
*)dp
+ sizeof(*dp
),
153 dstoptlen
- sizeof(*dp
));
159 fputs("[|DSTOPT]", stdout
);