]>
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.22 2002-06-11 17:08:50 itojun Exp $";
33 #include <sys/param.h>
35 #include <sys/types.h>
36 #include <sys/socket.h>
38 #include <netinet/in.h>
45 #include "interface.h"
46 #include "addrtoname.h"
51 * print an IP6 datagram.
54 ip6_print(register const u_char
*bp
, register u_int length
)
56 register const struct ip6_hdr
*ip6
;
59 register const u_char
*cp
;
64 ip6
= (const struct ip6_hdr
*)bp
;
68 * The IP6 header is not 16-byte aligned, so copy into abuf.
70 if ((u_long
)ip6
& 15) {
74 abuf
= malloc(snaplen
);
76 error("ip6_print: malloc");
78 memcpy(abuf
, ip6
, min(length
, snaplen
));
79 snapend
+= abuf
- (u_char
*)ip6
;
81 ip6
= (struct ip6_hdr
*)abuf
;
86 if (length
< sizeof (struct ip6_hdr
)) {
87 (void)printf("truncated-ip6 %d", length
);
90 advance
= sizeof(struct ip6_hdr
);
92 len
= ntohs(ip6
->ip6_plen
);
93 if (length
< len
+ advance
)
94 (void)printf("truncated-ip6 - %d bytes missing!",
95 len
+ advance
- length
);
97 cp
= (const u_char
*)ip6
;
99 while (cp
< snapend
) {
102 if (cp
== (const u_char
*)(ip6
+ 1)
103 && nh
!= IPPROTO_TCP
&& nh
!= IPPROTO_UDP
) {
104 (void)printf("%s > %s: ", ip6addr_string(&ip6
->ip6_src
),
105 ip6addr_string(&ip6
->ip6_dst
));
109 case IPPROTO_HOPOPTS
:
110 advance
= hbhopt_print(cp
);
113 case IPPROTO_DSTOPTS
:
114 advance
= dstopt_print(cp
);
117 case IPPROTO_FRAGMENT
:
118 advance
= frag6_print(cp
, (const u_char
*)ip6
);
119 if (snapend
<= cp
+ advance
)
124 case IPPROTO_ROUTING
:
125 advance
= rt6_print(cp
, (const u_char
*)ip6
);
129 tcp_print(cp
, len
+ sizeof(struct ip6_hdr
) - (cp
- bp
),
130 (const u_char
*)ip6
, fragmented
);
133 udp_print(cp
, len
+ sizeof(struct ip6_hdr
) - (cp
- bp
),
134 (const u_char
*)ip6
, fragmented
);
137 icmp6_print(cp
, (const u_char
*)ip6
);
140 advance
= ah_print(cp
, (const u_char
*)ip6
);
146 advance
= esp_print(cp
, (const u_char
*)ip6
, &enh
, &padlen
);
153 #ifndef IPPROTO_IPCOMP
154 #define IPPROTO_IPCOMP 108
159 advance
= ipcomp_print(cp
, (const u_char
*)ip6
, &enh
);
167 #define IPPROTO_PIM 103
173 #define IPPROTO_OSPF 89
176 ospf6_print(cp
, len
);
182 #define IPPROTO_IPV4 4
188 (void)printf("no next header");
192 (void)printf("ip-proto-%d %d", ip6
->ip6_nxt
, len
);
199 flow
= ntohl(ip6
->ip6_flow
);
202 if (flow
& 0x0f000000)
203 (void)printf(" [pri 0x%x]", (flow
& 0x0f000000) >> 24);
204 if (flow
& 0x00ffffff)
205 (void)printf(" [flowlabel 0x%x]", flow
& 0x00ffffff);
208 if (flow
& 0x0ff00000)
209 (void)printf(" [class 0x%x]", (flow
& 0x0ff00000) >> 20);
210 if (flow
& 0x000fffff)
211 (void)printf(" [flowlabel 0x%x]", flow
& 0x000fffff);
214 if (ip6
->ip6_hlim
<= 1)
215 (void)printf(" [hlim %d]", (int)ip6
->ip6_hlim
);
219 (void)printf("len %d", len
);
220 if (ip6
->ip6_hlim
> 1)
221 (void)printf(", hlim %d", (int)ip6
->ip6_hlim
);
226 (void)printf("[|ip6]");