4 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
24 #include <sys/cdefs.h>
27 static const char rcsid
[] _U_
=
28 "@(#) Header: /tcpdump/master/tcpdump/print-ip6.c,v 1.47.2.3 2005/09/20 06:05:38 guy Exp";
30 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
40 #include <tcpdump-stdinc.h>
46 #include "interface.h"
47 #include "addrtoname.h"
54 * print an IP6 datagram.
57 ip6_print(register const u_char
*bp
, register u_int length
)
59 register const struct ip6_hdr
*ip6
;
63 register const u_char
*cp
;
64 register u_int payload_len
;
69 ip6
= (const struct ip6_hdr
*)bp
;
72 if (length
< sizeof (struct ip6_hdr
)) {
73 (void)printf("truncated-ip6 %u", length
);
80 payload_len
= EXTRACT_16BITS(&ip6
->ip6_plen
);
81 len
= payload_len
+ sizeof(struct ip6_hdr
);
83 (void)printf("truncated-ip6 - %u bytes missing!",
87 flow
= EXTRACT_32BITS(&ip6
->ip6_flow
);
91 if (flow
& 0x0f000000)
92 (void)printf("pri 0x%02x, ", (flow
& 0x0f000000) >> 24);
93 if (flow
& 0x00ffffff)
94 (void)printf("flowlabel 0x%06x, ", flow
& 0x00ffffff);
97 if (flow
& 0x0ff00000)
98 (void)printf("class 0x%02x, ", (flow
& 0x0ff00000) >> 20);
99 if (flow
& 0x000fffff)
100 (void)printf("flowlabel 0x%05x, ", flow
& 0x000fffff);
103 (void)printf("hlim %u, next-header: %s (%u), length: %u) ",
105 tok2str(ipproto_values
,"unknown",ip6
->ip6_nxt
),
111 * Cut off the snapshot length to the end of the IP payload.
117 cp
= (const u_char
*)ip6
;
118 advance
= sizeof(struct ip6_hdr
);
120 while (cp
< snapend
&& advance
> 0) {
124 if (cp
== (const u_char
*)(ip6
+ 1) &&
125 nh
!= IPPROTO_TCP
&& nh
!= IPPROTO_UDP
&&
126 nh
!= IPPROTO_DCCP
&& nh
!= IPPROTO_SCTP
) {
127 (void)printf("%s > %s: ", ip6addr_string(&ip6
->ip6_src
),
128 ip6addr_string(&ip6
->ip6_dst
));
132 case IPPROTO_HOPOPTS
:
133 advance
= hbhopt_print(cp
);
136 case IPPROTO_DSTOPTS
:
137 advance
= dstopt_print(cp
);
140 case IPPROTO_FRAGMENT
:
141 advance
= frag6_print(cp
, (const u_char
*)ip6
);
142 if (snapend
<= cp
+ advance
)
148 case IPPROTO_MOBILITY_OLD
:
149 case IPPROTO_MOBILITY
:
151 * XXX - we don't use "advance"; the current
152 * "Mobility Support in IPv6" draft
153 * (draft-ietf-mobileip-ipv6-24) says that
154 * the next header field in a mobility header
155 * should be IPPROTO_NONE, but speaks of
156 * the possiblity of a future extension in
157 * which payload can be piggybacked atop a
160 advance
= mobility_print(cp
, (const u_char
*)ip6
);
163 case IPPROTO_ROUTING
:
164 advance
= rt6_print(cp
, (const u_char
*)ip6
);
168 sctp_print(cp
, (const u_char
*)ip6
, len
);
171 dccp_print(cp
, (const u_char
*)ip6
, len
);
174 tcp_print(cp
, len
, (const u_char
*)ip6
, fragmented
);
177 udp_print(cp
, len
, (const u_char
*)ip6
, fragmented
);
180 icmp6_print(cp
, len
, (const u_char
*)ip6
, fragmented
);
183 advance
= ah_print(cp
);
189 advance
= esp_print(gndo
, cp
, len
, (const u_char
*)ip6
, &enh
, &padlen
);
197 advance
= ipcomp_print(cp
, &enh
);
207 ospf6_print(cp
, len
);
215 ip_print(gndo
, cp
, len
);
219 pgm_print(cp
, len
, (const u_char
*)ip6
);
231 (void)printf("no next header");
235 (void)printf("ip-proto-%d %d", ip6
->ip6_nxt
, len
);
242 (void)printf("[|ip6]");