]> The Tcpdump Group git mirrors - tcpdump/blob - print-ip6.c
Get rid of FDDI cruft left over from copying fddi.h to ipfc.h and
[tcpdump] / print-ip6.c
1 /*
2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
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
16 * written permission.
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.
20 */
21
22 #ifndef lint
23 static const char rcsid[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-ip6.c,v 1.27 2002-10-18 04:40:03 itojun Exp $";
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #ifdef INET6
32
33 #include <tcpdump-stdinc.h>
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38
39 #include "interface.h"
40 #include "addrtoname.h"
41
42 #include "ip6.h"
43
44 /*
45 * print an IP6 datagram.
46 */
47 void
48 ip6_print(register const u_char *bp, register u_int length)
49 {
50 register const struct ip6_hdr *ip6;
51 register int advance;
52 register u_int len;
53 register const u_char *cp;
54 int nh;
55 int fragmented = 0;
56 u_int flow;
57
58 ip6 = (const struct ip6_hdr *)bp;
59
60 TCHECK(*ip6);
61 if (length < sizeof (struct ip6_hdr)) {
62 (void)printf("truncated-ip6 %d", length);
63 return;
64 }
65 advance = sizeof(struct ip6_hdr);
66
67 len = ntohs(ip6->ip6_plen);
68 if (length < len + advance)
69 (void)printf("truncated-ip6 - %d bytes missing!",
70 len + advance - length);
71
72 cp = (const u_char *)ip6;
73 nh = ip6->ip6_nxt;
74 while (cp < snapend) {
75 cp += advance;
76
77 if (cp == (const u_char *)(ip6 + 1)
78 && nh != IPPROTO_TCP && nh != IPPROTO_UDP) {
79 (void)printf("%s > %s: ", ip6addr_string(&ip6->ip6_src),
80 ip6addr_string(&ip6->ip6_dst));
81 }
82
83 switch (nh) {
84 case IPPROTO_HOPOPTS:
85 advance = hbhopt_print(cp);
86 nh = *cp;
87 break;
88 case IPPROTO_DSTOPTS:
89 advance = dstopt_print(cp);
90 nh = *cp;
91 break;
92 case IPPROTO_FRAGMENT:
93 advance = frag6_print(cp, (const u_char *)ip6);
94 if (snapend <= cp + advance)
95 goto end;
96 nh = *cp;
97 fragmented = 1;
98 break;
99 #ifndef IPPROTO_MOBILITY
100 #define IPPROTO_MOBILITY 62
101 #endif
102 case IPPROTO_MOBILITY:
103 /*
104 * XXX - we don't use "advance"; is this
105 * header always a final header?
106 */
107 advance = mobility_print(cp, (const u_char *)ip6);
108 nh = *cp;
109 goto end;
110 case IPPROTO_ROUTING:
111 advance = rt6_print(cp, (const u_char *)ip6);
112 nh = *cp;
113 break;
114 case IPPROTO_TCP:
115 tcp_print(cp, len + sizeof(struct ip6_hdr) - (cp - bp),
116 (const u_char *)ip6, fragmented);
117 goto end;
118 case IPPROTO_UDP:
119 udp_print(cp, len + sizeof(struct ip6_hdr) - (cp - bp),
120 (const u_char *)ip6, fragmented);
121 goto end;
122 case IPPROTO_ICMPV6:
123 icmp6_print(cp, (const u_char *)ip6);
124 goto end;
125 case IPPROTO_AH:
126 advance = ah_print(cp);
127 nh = *cp;
128 break;
129 case IPPROTO_ESP:
130 {
131 int enh, padlen;
132 advance = esp_print(cp, (const u_char *)ip6, &enh, &padlen);
133 if (enh < 0)
134 goto end;
135 nh = enh & 0xff;
136 len -= padlen;
137 break;
138 }
139 #ifndef IPPROTO_IPCOMP
140 #define IPPROTO_IPCOMP 108
141 #endif
142 case IPPROTO_IPCOMP:
143 {
144 int enh;
145 advance = ipcomp_print(cp, &enh);
146 if (enh < 0)
147 goto end;
148 nh = enh & 0xff;
149 break;
150 }
151
152 #ifndef IPPROTO_PIM
153 #define IPPROTO_PIM 103
154 #endif
155 case IPPROTO_PIM:
156 pim_print(cp, len);
157 goto end;
158 #ifndef IPPROTO_OSPF
159 #define IPPROTO_OSPF 89
160 #endif
161 case IPPROTO_OSPF:
162 ospf6_print(cp, len);
163 goto end;
164 case IPPROTO_IPV6:
165 ip6_print(cp, len);
166 goto end;
167 #ifndef IPPROTO_IPV4
168 #define IPPROTO_IPV4 4
169 #endif
170 case IPPROTO_IPV4:
171 ip_print(cp, len);
172 goto end;
173 case IPPROTO_NONE:
174 (void)printf("no next header");
175 goto end;
176
177 default:
178 (void)printf("ip-proto-%d %d", ip6->ip6_nxt, len);
179 goto end;
180 }
181 }
182
183 end:
184
185 flow = ntohl(ip6->ip6_flow);
186 #if 0
187 /* rfc1883 */
188 if (flow & 0x0f000000)
189 (void)printf(" [pri 0x%x]", (flow & 0x0f000000) >> 24);
190 if (flow & 0x00ffffff)
191 (void)printf(" [flowlabel 0x%x]", flow & 0x00ffffff);
192 #else
193 /* RFC 2460 */
194 if (flow & 0x0ff00000)
195 (void)printf(" [class 0x%x]", (flow & 0x0ff00000) >> 20);
196 if (flow & 0x000fffff)
197 (void)printf(" [flowlabel 0x%x]", flow & 0x000fffff);
198 #endif
199
200 if (ip6->ip6_hlim <= 1)
201 (void)printf(" [hlim %d]", (int)ip6->ip6_hlim);
202
203 if (vflag) {
204 printf(" (");
205 (void)printf("len %d", len);
206 if (ip6->ip6_hlim > 1)
207 (void)printf(", hlim %d", (int)ip6->ip6_hlim);
208 printf(")");
209 }
210 return;
211 trunc:
212 (void)printf("[|ip6]");
213 }
214
215 #endif /* INET6 */