2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 static const char rcsid
[] _U_
=
24 "@(#) $Header: /tcpdump/master/tcpdump/print-ip6.c,v 1.52 2007-09-21 07:05:33 hannes Exp $";
33 #include <tcpdump-stdinc.h>
39 #include "netdissect.h"
40 #include "interface.h"
41 #include "addrtoname.h"
48 * Compute a V6-style checksum by building a pseudoheader.
51 nextproto6_cksum(const struct ip6_hdr
*ip6
, const u_int8_t
*data
,
52 u_int len
, u_int next_proto
)
55 struct in6_addr ph_src
;
56 struct in6_addr ph_dst
;
61 struct cksum_vec vec
[2];
64 memset(&ph
, 0, sizeof(ph
));
65 ph
.ph_src
= ip6
->ip6_src
;
66 ph
.ph_dst
= ip6
->ip6_dst
;
67 ph
.ph_len
= htonl(len
);
68 ph
.ph_nxt
= next_proto
;
70 vec
[0].ptr
= (const u_int8_t
*)(void *)&ph
;
71 vec
[0].len
= sizeof(ph
);
75 return in_cksum(vec
, 2);
79 * print an IP6 datagram.
82 ip6_print(netdissect_options
*ndo
, const u_char
*bp
, u_int length
)
84 register const struct ip6_hdr
*ip6
;
88 register const u_char
*cp
;
89 register u_int payload_len
;
94 ip6
= (const struct ip6_hdr
*)bp
;
97 if (length
< sizeof (struct ip6_hdr
)) {
98 (void)ND_PRINT((ndo
, "truncated-ip6 %u", length
));
103 ND_PRINT((ndo
, "IP6 "));
105 payload_len
= EXTRACT_16BITS(&ip6
->ip6_plen
);
106 len
= payload_len
+ sizeof(struct ip6_hdr
);
108 (void)ND_PRINT((ndo
, "truncated-ip6 - %u bytes missing!",
111 if (ndo
->ndo_vflag
) {
112 flow
= EXTRACT_32BITS(&ip6
->ip6_flow
);
113 ND_PRINT((ndo
, "("));
116 if (flow
& 0x0f000000)
117 (void)ND_PRINT((ndo
, "pri 0x%02x, ", (flow
& 0x0f000000) >> 24));
118 if (flow
& 0x00ffffff)
119 (void)ND_PRINT((ndo
, "flowlabel 0x%06x, ", flow
& 0x00ffffff));
122 if (flow
& 0x0ff00000)
123 (void)ND_PRINT((ndo
, "class 0x%02x, ", (flow
& 0x0ff00000) >> 20));
124 if (flow
& 0x000fffff)
125 (void)ND_PRINT((ndo
, "flowlabel 0x%05x, ", flow
& 0x000fffff));
128 (void)ND_PRINT((ndo
, "hlim %u, next-header %s (%u) payload length: %u) ",
130 tok2str(ipproto_values
,"unknown",ip6
->ip6_nxt
),
136 * Cut off the snapshot length to the end of the IP payload.
139 if (ipend
< ndo
->ndo_snapend
)
140 ndo
->ndo_snapend
= ipend
;
142 cp
= (const u_char
*)ip6
;
143 advance
= sizeof(struct ip6_hdr
);
145 while (cp
< ndo
->ndo_snapend
&& advance
> 0) {
149 if (cp
== (const u_char
*)(ip6
+ 1) &&
150 nh
!= IPPROTO_TCP
&& nh
!= IPPROTO_UDP
&&
151 nh
!= IPPROTO_DCCP
&& nh
!= IPPROTO_SCTP
) {
152 (void)ND_PRINT((ndo
, "%s > %s: ", ip6addr_string(&ip6
->ip6_src
),
153 ip6addr_string(&ip6
->ip6_dst
)));
157 case IPPROTO_HOPOPTS
:
158 advance
= hbhopt_print(cp
);
161 case IPPROTO_DSTOPTS
:
162 advance
= dstopt_print(cp
);
165 case IPPROTO_FRAGMENT
:
166 advance
= frag6_print(cp
, (const u_char
*)ip6
);
167 if (ndo
->ndo_snapend
<= cp
+ advance
)
173 case IPPROTO_MOBILITY_OLD
:
174 case IPPROTO_MOBILITY
:
176 * XXX - we don't use "advance"; the current
177 * "Mobility Support in IPv6" draft
178 * (draft-ietf-mobileip-ipv6-24) says that
179 * the next header field in a mobility header
180 * should be IPPROTO_NONE, but speaks of
181 * the possiblity of a future extension in
182 * which payload can be piggybacked atop a
185 advance
= mobility_print(cp
, (const u_char
*)ip6
);
188 case IPPROTO_ROUTING
:
189 advance
= rt6_print(cp
, (const u_char
*)ip6
);
193 sctp_print(cp
, (const u_char
*)ip6
, len
);
196 dccp_print(cp
, (const u_char
*)ip6
, len
);
199 tcp_print(cp
, len
, (const u_char
*)ip6
, fragmented
);
202 udp_print(cp
, len
, (const u_char
*)ip6
, fragmented
);
205 icmp6_print(ndo
, cp
, len
, (const u_char
*)ip6
, fragmented
);
208 advance
= ah_print(cp
);
214 advance
= esp_print(ndo
, cp
, len
, (const u_char
*)ip6
, &enh
, &padlen
);
222 advance
= ipcomp_print(cp
, &enh
);
228 pim_print(cp
, len
, nextproto6_cksum(ip6
, cp
, len
,
233 ospf6_print(cp
, len
);
237 ip6_print(ndo
, cp
, len
);
241 ip_print(ndo
, cp
, len
);
245 pgm_print(cp
, len
, (const u_char
*)ip6
);
257 (void)ND_PRINT((ndo
, "no next header"));
261 (void)ND_PRINT((ndo
, "ip-proto-%d %d", nh
, len
));
268 (void)ND_PRINT((ndo
, "[|ip6]"));