]>
The Tcpdump Group git mirrors - tcpdump/blob - print-ip6.c
45508ced6cbf11a0ea5eb537f540488c0a3d1d97
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.
26 #include <netdissect-stdinc.h>
30 #include "netdissect.h"
31 #include "addrtoname.h"
38 * Compute a V6-style checksum by building a pseudoheader.
41 nextproto6_cksum(const struct ip6_hdr
*ip6
, const uint8_t *data
,
42 u_int len
, u_int covlen
, u_int next_proto
)
45 struct in6_addr ph_src
;
46 struct in6_addr ph_dst
;
51 struct cksum_vec vec
[2];
54 memset(&ph
, 0, sizeof(ph
));
55 UNALIGNED_MEMCPY(&ph
.ph_src
, &ip6
->ip6_src
, sizeof (struct in6_addr
));
56 UNALIGNED_MEMCPY(&ph
.ph_dst
, &ip6
->ip6_dst
, sizeof (struct in6_addr
));
57 ph
.ph_len
= htonl(len
);
58 ph
.ph_nxt
= next_proto
;
60 vec
[0].ptr
= (const uint8_t *)(void *)&ph
;
61 vec
[0].len
= sizeof(ph
);
65 return in_cksum(vec
, 2);
69 * print an IP6 datagram.
72 ip6_print(netdissect_options
*ndo
, const u_char
*bp
, u_int length
)
74 register const struct ip6_hdr
*ip6
;
78 register const u_char
*cp
;
79 register u_int payload_len
;
84 ip6
= (const struct ip6_hdr
*)bp
;
87 if (length
< sizeof (struct ip6_hdr
)) {
88 ND_PRINT((ndo
, "truncated-ip6 %u", length
));
93 ND_PRINT((ndo
, "IP6 "));
95 if (IP6_VERSION(ip6
) != 6) {
96 ND_PRINT((ndo
,"version error: %u != 6", IP6_VERSION(ip6
)));
100 payload_len
= EXTRACT_16BITS(&ip6
->ip6_plen
);
101 len
= payload_len
+ sizeof(struct ip6_hdr
);
103 ND_PRINT((ndo
, "truncated-ip6 - %u bytes missing!",
106 if (ndo
->ndo_vflag
) {
107 flow
= EXTRACT_32BITS(&ip6
->ip6_flow
);
108 ND_PRINT((ndo
, "("));
111 if (flow
& 0x0f000000)
112 ND_PRINT((ndo
, "pri 0x%02x, ", (flow
& 0x0f000000) >> 24));
113 if (flow
& 0x00ffffff)
114 ND_PRINT((ndo
, "flowlabel 0x%06x, ", flow
& 0x00ffffff));
117 if (flow
& 0x0ff00000)
118 ND_PRINT((ndo
, "class 0x%02x, ", (flow
& 0x0ff00000) >> 20));
119 if (flow
& 0x000fffff)
120 ND_PRINT((ndo
, "flowlabel 0x%05x, ", flow
& 0x000fffff));
123 ND_PRINT((ndo
, "hlim %u, next-header %s (%u) payload length: %u) ",
125 tok2str(ipproto_values
,"unknown",ip6
->ip6_nxt
),
131 * Cut off the snapshot length to the end of the IP payload.
134 if (ipend
< ndo
->ndo_snapend
)
135 ndo
->ndo_snapend
= ipend
;
137 cp
= (const u_char
*)ip6
;
138 advance
= sizeof(struct ip6_hdr
);
140 while (cp
< ndo
->ndo_snapend
&& advance
> 0) {
144 if (cp
== (const u_char
*)(ip6
+ 1) &&
145 nh
!= IPPROTO_TCP
&& nh
!= IPPROTO_UDP
&&
146 nh
!= IPPROTO_DCCP
&& nh
!= IPPROTO_SCTP
) {
147 ND_PRINT((ndo
, "%s > %s: ", ip6addr_string(ndo
, &ip6
->ip6_src
),
148 ip6addr_string(ndo
, &ip6
->ip6_dst
)));
152 case IPPROTO_HOPOPTS
:
153 advance
= hbhopt_print(ndo
, cp
);
156 case IPPROTO_DSTOPTS
:
157 advance
= dstopt_print(ndo
, cp
);
160 case IPPROTO_FRAGMENT
:
161 advance
= frag6_print(ndo
, cp
, (const u_char
*)ip6
);
162 if (ndo
->ndo_snapend
<= cp
+ advance
)
168 case IPPROTO_MOBILITY_OLD
:
169 case IPPROTO_MOBILITY
:
171 * XXX - we don't use "advance"; the current
172 * "Mobility Support in IPv6" draft
173 * (draft-ietf-mobileip-ipv6-24) says that
174 * the next header field in a mobility header
175 * should be IPPROTO_NONE, but speaks of
176 * the possiblity of a future extension in
177 * which payload can be piggybacked atop a
180 advance
= mobility_print(ndo
, cp
, (const u_char
*)ip6
);
183 case IPPROTO_ROUTING
:
184 advance
= rt6_print(ndo
, cp
, (const u_char
*)ip6
);
188 sctp_print(ndo
, cp
, (const u_char
*)ip6
, len
);
191 dccp_print(ndo
, cp
, (const u_char
*)ip6
, len
);
194 tcp_print(ndo
, cp
, len
, (const u_char
*)ip6
, fragmented
);
197 udp_print(ndo
, cp
, len
, (const u_char
*)ip6
, fragmented
);
200 icmp6_print(ndo
, cp
, len
, (const u_char
*)ip6
, fragmented
);
203 advance
= ah_print(ndo
, cp
);
209 advance
= esp_print(ndo
, cp
, len
, (const u_char
*)ip6
, &enh
, &padlen
);
217 advance
= ipcomp_print(ndo
, cp
, &enh
);
223 pim_print(ndo
, cp
, len
, (const u_char
*)ip6
);
227 ospf6_print(ndo
, cp
, len
);
231 ip6_print(ndo
, cp
, len
);
235 ip_print(ndo
, cp
, len
);
239 pgm_print(ndo
, cp
, len
, (const u_char
*)ip6
);
243 gre_print(ndo
, cp
, len
);
247 rsvp_print(ndo
, cp
, len
);
251 ND_PRINT((ndo
, "no next header"));
255 ND_PRINT((ndo
, "ip-proto-%d %d", nh
, len
));
262 ND_PRINT((ndo
, "[|ip6]"));