Fix markup. Fix backslashes to surive roff.
[netbsd-mini2440.git] / dist / tcpdump / print-ip6.c
blobe28465b491177b85be6d53a0bf64e3e5708b7a1d
1 /* $NetBSD$ */
3 /*
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
18 * written permission.
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>
25 #ifndef lint
26 #if 0
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";
29 #else
30 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
31 #endif
32 #endif
34 #ifdef HAVE_CONFIG_H
35 #include "config.h"
36 #endif
38 #ifdef INET6
40 #include <tcpdump-stdinc.h>
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
46 #include "interface.h"
47 #include "addrtoname.h"
48 #include "extract.h"
50 #include "ip6.h"
51 #include "ipproto.h"
54 * print an IP6 datagram.
56 void
57 ip6_print(register const u_char *bp, register u_int length)
59 register const struct ip6_hdr *ip6;
60 register int advance;
61 u_int len;
62 const u_char *ipend;
63 register const u_char *cp;
64 register u_int payload_len;
65 int nh;
66 int fragmented = 0;
67 u_int flow;
69 ip6 = (const struct ip6_hdr *)bp;
71 TCHECK(*ip6);
72 if (length < sizeof (struct ip6_hdr)) {
73 (void)printf("truncated-ip6 %u", length);
74 return;
77 if (!eflag)
78 printf("IP6 ");
80 payload_len = EXTRACT_16BITS(&ip6->ip6_plen);
81 len = payload_len + sizeof(struct ip6_hdr);
82 if (length < len)
83 (void)printf("truncated-ip6 - %u bytes missing!",
84 len - length);
86 if (vflag) {
87 flow = EXTRACT_32BITS(&ip6->ip6_flow);
88 printf("(");
89 #if 0
90 /* rfc1883 */
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);
95 #else
96 /* RFC 2460 */
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);
101 #endif
103 (void)printf("hlim %u, next-header: %s (%u), length: %u) ",
104 ip6->ip6_hlim,
105 tok2str(ipproto_values,"unknown",ip6->ip6_nxt),
106 ip6->ip6_nxt,
107 payload_len);
111 * Cut off the snapshot length to the end of the IP payload.
113 ipend = bp + len;
114 if (ipend < snapend)
115 snapend = ipend;
117 cp = (const u_char *)ip6;
118 advance = sizeof(struct ip6_hdr);
119 nh = ip6->ip6_nxt;
120 while (cp < snapend && advance > 0) {
121 cp += advance;
122 len -= advance;
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));
131 switch (nh) {
132 case IPPROTO_HOPOPTS:
133 advance = hbhopt_print(cp);
134 nh = *cp;
135 break;
136 case IPPROTO_DSTOPTS:
137 advance = dstopt_print(cp);
138 nh = *cp;
139 break;
140 case IPPROTO_FRAGMENT:
141 advance = frag6_print(cp, (const u_char *)ip6);
142 if (snapend <= cp + advance)
143 return;
144 nh = *cp;
145 fragmented = 1;
146 break;
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
158 * mobility header.
160 advance = mobility_print(cp, (const u_char *)ip6);
161 nh = *cp;
162 return;
163 case IPPROTO_ROUTING:
164 advance = rt6_print(cp, (const u_char *)ip6);
165 nh = *cp;
166 break;
167 case IPPROTO_SCTP:
168 sctp_print(cp, (const u_char *)ip6, len);
169 return;
170 case IPPROTO_DCCP:
171 dccp_print(cp, (const u_char *)ip6, len);
172 return;
173 case IPPROTO_TCP:
174 tcp_print(cp, len, (const u_char *)ip6, fragmented);
175 return;
176 case IPPROTO_UDP:
177 udp_print(cp, len, (const u_char *)ip6, fragmented);
178 return;
179 case IPPROTO_ICMPV6:
180 icmp6_print(cp, len, (const u_char *)ip6, fragmented);
181 return;
182 case IPPROTO_AH:
183 advance = ah_print(cp);
184 nh = *cp;
185 break;
186 case IPPROTO_ESP:
188 int enh, padlen;
189 advance = esp_print(gndo, cp, len, (const u_char *)ip6, &enh, &padlen);
190 nh = enh & 0xff;
191 len -= padlen;
192 break;
194 case IPPROTO_IPCOMP:
196 int enh;
197 advance = ipcomp_print(cp, &enh);
198 nh = enh & 0xff;
199 break;
202 case IPPROTO_PIM:
203 pim_print(cp, len);
204 return;
206 case IPPROTO_OSPF:
207 ospf6_print(cp, len);
208 return;
210 case IPPROTO_IPV6:
211 ip6_print(cp, len);
212 return;
214 case IPPROTO_IPV4:
215 ip_print(gndo, cp, len);
216 return;
218 case IPPROTO_PGM:
219 pgm_print(cp, len, (const u_char *)ip6);
220 return;
222 case IPPROTO_GRE:
223 gre_print(cp, len);
224 return;
226 case IPPROTO_RSVP:
227 rsvp_print(cp, len);
228 return;
230 case IPPROTO_NONE:
231 (void)printf("no next header");
232 return;
234 default:
235 (void)printf("ip-proto-%d %d", ip6->ip6_nxt, len);
236 return;
240 return;
241 trunc:
242 (void)printf("[|ip6]");
245 #endif /* INET6 */