]>
The Tcpdump Group git mirrors - tcpdump/blob - print-ip6.c
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.
22 #define NETDISSECT_REWORKED
27 #include <tcpdump-stdinc.h>
31 #include "interface.h"
32 #include "addrtoname.h"
41 * Compute a V6-style checksum by building a pseudoheader.
44 nextproto6_cksum(const struct ip6_hdr
*ip6
, const uint8_t *data
,
45 u_int len
, u_int covlen
, u_int next_proto
)
48 struct in6_addr ph_src
;
49 struct in6_addr ph_dst
;
54 struct cksum_vec vec
[2];
57 memset(&ph
, 0, sizeof(ph
));
58 UNALIGNED_MEMCPY(&ph
.ph_src
, &ip6
->ip6_src
, sizeof (struct in6_addr
));
59 UNALIGNED_MEMCPY(&ph
.ph_dst
, &ip6
->ip6_dst
, sizeof (struct in6_addr
));
60 ph
.ph_len
= htonl(len
);
61 ph
.ph_nxt
= next_proto
;
63 vec
[0].ptr
= (const uint8_t *)(void *)&ph
;
64 vec
[0].len
= sizeof(ph
);
68 return in_cksum(vec
, 2);
72 * print an IP6 datagram.
75 ip6_print(netdissect_options
*ndo
, const u_char
*bp
, u_int length
)
77 register const struct ip6_hdr
*ip6
;
81 register const u_char
*cp
;
82 register u_int payload_len
;
87 ip6
= (const struct ip6_hdr
*)bp
;
90 if (length
< sizeof (struct ip6_hdr
)) {
91 ND_PRINT((ndo
, "truncated-ip6 %u", length
));
96 ND_PRINT((ndo
, "IP6 "));
98 if (IP6_VERSION(ip6
) != 6) {
99 ND_PRINT((ndo
,"version error: %u != 6", IP6_VERSION(ip6
)));
103 payload_len
= EXTRACT_16BITS(&ip6
->ip6_plen
);
104 len
= payload_len
+ sizeof(struct ip6_hdr
);
106 ND_PRINT((ndo
, "truncated-ip6 - %u bytes missing!",
109 if (ndo
->ndo_vflag
) {
110 flow
= EXTRACT_32BITS(&ip6
->ip6_flow
);
111 ND_PRINT((ndo
, "("));
114 if (flow
& 0x0f000000)
115 ND_PRINT((ndo
, "pri 0x%02x, ", (flow
& 0x0f000000) >> 24));
116 if (flow
& 0x00ffffff)
117 ND_PRINT((ndo
, "flowlabel 0x%06x, ", flow
& 0x00ffffff));
120 if (flow
& 0x0ff00000)
121 ND_PRINT((ndo
, "class 0x%02x, ", (flow
& 0x0ff00000) >> 20));
122 if (flow
& 0x000fffff)
123 ND_PRINT((ndo
, "flowlabel 0x%05x, ", flow
& 0x000fffff));
126 ND_PRINT((ndo
, "hlim %u, next-header %s (%u) payload length: %u) ",
128 tok2str(ipproto_values
,"unknown",ip6
->ip6_nxt
),
134 * Cut off the snapshot length to the end of the IP payload.
137 if (ipend
< ndo
->ndo_snapend
)
138 ndo
->ndo_snapend
= ipend
;
140 cp
= (const u_char
*)ip6
;
141 advance
= sizeof(struct ip6_hdr
);
143 while (cp
< ndo
->ndo_snapend
&& advance
> 0) {
147 if (cp
== (const u_char
*)(ip6
+ 1) &&
148 nh
!= IPPROTO_TCP
&& nh
!= IPPROTO_UDP
&&
149 nh
!= IPPROTO_DCCP
&& nh
!= IPPROTO_SCTP
) {
150 ND_PRINT((ndo
, "%s > %s: ", ip6addr_string(ndo
, &ip6
->ip6_src
),
151 ip6addr_string(ndo
, &ip6
->ip6_dst
)));
155 case IPPROTO_HOPOPTS
:
156 advance
= hbhopt_print(ndo
, cp
);
159 case IPPROTO_DSTOPTS
:
160 advance
= dstopt_print(ndo
, cp
);
163 case IPPROTO_FRAGMENT
:
164 advance
= frag6_print(ndo
, cp
, (const u_char
*)ip6
);
165 if (ndo
->ndo_snapend
<= cp
+ advance
)
171 case IPPROTO_MOBILITY_OLD
:
172 case IPPROTO_MOBILITY
:
174 * XXX - we don't use "advance"; the current
175 * "Mobility Support in IPv6" draft
176 * (draft-ietf-mobileip-ipv6-24) says that
177 * the next header field in a mobility header
178 * should be IPPROTO_NONE, but speaks of
179 * the possiblity of a future extension in
180 * which payload can be piggybacked atop a
183 advance
= mobility_print(ndo
, cp
, (const u_char
*)ip6
);
186 case IPPROTO_ROUTING
:
187 advance
= rt6_print(ndo
, cp
, (const u_char
*)ip6
);
191 sctp_print(ndo
, cp
, (const u_char
*)ip6
, len
);
194 dccp_print(ndo
, cp
, (const u_char
*)ip6
, len
);
197 tcp_print(ndo
, cp
, len
, (const u_char
*)ip6
, fragmented
);
200 udp_print(ndo
, cp
, len
, (const u_char
*)ip6
, fragmented
);
203 icmp6_print(ndo
, cp
, len
, (const u_char
*)ip6
, fragmented
);
206 advance
= ah_print(ndo
, cp
);
212 advance
= esp_print(ndo
, cp
, len
, (const u_char
*)ip6
, &enh
, &padlen
);
220 advance
= ipcomp_print(ndo
, cp
, &enh
);
226 pim_print(ndo
, cp
, len
, nextproto6_cksum(ip6
, cp
, len
, len
,
231 ospf6_print(ndo
, cp
, len
);
235 ip6_print(ndo
, cp
, len
);
239 ip_print(ndo
, cp
, len
);
243 pgm_print(ndo
, cp
, len
, (const u_char
*)ip6
);
247 gre_print(ndo
, cp
, len
);
251 rsvp_print(ndo
, cp
, len
);
255 ND_PRINT((ndo
, "no next header"));
259 ND_PRINT((ndo
, "ip-proto-%d %d", nh
, len
));
266 ND_PRINT((ndo
, "[|ip6]"));
272 ip6_print(netdissect_options
*ndo
, const u_char
*bp _U_
, u_int length
)
274 ND_PRINT((ndo
, "IP6, length: %u (printing not supported)", length
));