]>
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.
23 static const char rcsid
[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-ip6.c,v 1.24 2002-08-01 08:53:10 risso Exp $";
33 #include <tcpdump-stdinc.h>
39 #include "interface.h"
40 #include "addrtoname.h"
45 * print an IP6 datagram.
48 ip6_print(register const u_char
*bp
, register u_int length
)
50 register const struct ip6_hdr
*ip6
;
53 register const u_char
*cp
;
58 ip6
= (const struct ip6_hdr
*)bp
;
62 * The IP6 header is not 16-byte aligned, so copy into abuf.
64 if ((u_long
)ip6
& 15) {
68 abuf
= malloc(snaplen
);
70 error("ip6_print: malloc");
72 memcpy(abuf
, ip6
, min(length
, snaplen
));
73 snapend
+= abuf
- (u_char
*)ip6
;
75 ip6
= (struct ip6_hdr
*)abuf
;
80 if (length
< sizeof (struct ip6_hdr
)) {
81 (void)printf("truncated-ip6 %d", length
);
84 advance
= sizeof(struct ip6_hdr
);
86 len
= ntohs(ip6
->ip6_plen
);
87 if (length
< len
+ advance
)
88 (void)printf("truncated-ip6 - %d bytes missing!",
89 len
+ advance
- length
);
91 cp
= (const u_char
*)ip6
;
93 while (cp
< snapend
) {
96 if (cp
== (const u_char
*)(ip6
+ 1)
97 && nh
!= IPPROTO_TCP
&& nh
!= IPPROTO_UDP
) {
98 (void)printf("%s > %s: ", ip6addr_string(&ip6
->ip6_src
),
99 ip6addr_string(&ip6
->ip6_dst
));
103 case IPPROTO_HOPOPTS
:
104 advance
= hbhopt_print(cp
);
107 case IPPROTO_DSTOPTS
:
108 advance
= dstopt_print(cp
);
111 case IPPROTO_FRAGMENT
:
112 advance
= frag6_print(cp
, (const u_char
*)ip6
);
113 if (snapend
<= cp
+ advance
)
118 #ifndef IPPROTO_MOBILITY
119 #define IPPROTO_MOBILITY 62
121 case IPPROTO_MOBILITY
:
122 advance
= mobility_print(cp
, (const u_char
*)ip6
);
125 case IPPROTO_ROUTING
:
126 advance
= rt6_print(cp
, (const u_char
*)ip6
);
130 tcp_print(cp
, len
+ sizeof(struct ip6_hdr
) - (cp
- bp
),
131 (const u_char
*)ip6
, fragmented
);
134 udp_print(cp
, len
+ sizeof(struct ip6_hdr
) - (cp
- bp
),
135 (const u_char
*)ip6
, fragmented
);
138 icmp6_print(cp
, (const u_char
*)ip6
);
141 advance
= ah_print(cp
, (const u_char
*)ip6
);
147 advance
= esp_print(cp
, (const u_char
*)ip6
, &enh
, &padlen
);
154 #ifndef IPPROTO_IPCOMP
155 #define IPPROTO_IPCOMP 108
160 advance
= ipcomp_print(cp
, (const u_char
*)ip6
, &enh
);
168 #define IPPROTO_PIM 103
174 #define IPPROTO_OSPF 89
177 ospf6_print(cp
, len
);
183 #define IPPROTO_IPV4 4
189 (void)printf("no next header");
193 (void)printf("ip-proto-%d %d", ip6
->ip6_nxt
, len
);
200 flow
= ntohl(ip6
->ip6_flow
);
203 if (flow
& 0x0f000000)
204 (void)printf(" [pri 0x%x]", (flow
& 0x0f000000) >> 24);
205 if (flow
& 0x00ffffff)
206 (void)printf(" [flowlabel 0x%x]", flow
& 0x00ffffff);
209 if (flow
& 0x0ff00000)
210 (void)printf(" [class 0x%x]", (flow
& 0x0ff00000) >> 20);
211 if (flow
& 0x000fffff)
212 (void)printf(" [flowlabel 0x%x]", flow
& 0x000fffff);
215 if (ip6
->ip6_hlim
<= 1)
216 (void)printf(" [hlim %d]", (int)ip6
->ip6_hlim
);
220 (void)printf("len %d", len
);
221 if (ip6
->ip6_hlim
> 1)
222 (void)printf(", hlim %d", (int)ip6
->ip6_hlim
);
227 (void)printf("[|ip6]");