]>
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 "@(#) /master/usr.sbin/tcpdump/tcpdump/print-ip.c,v 2.1 1995/02/03 18:14:45 polk Exp (LBL)";
29 #include <sys/param.h>
31 #include <sys/types.h>
32 #include <sys/socket.h>
34 #include <netinet/in.h>
35 #include <netinet/in_systm.h>
36 #include <netinet/ip.h>
37 #include <netinet/ip_var.h>
38 #include <netinet/udp.h>
39 #include <netinet/udp_var.h>
40 #include <netinet/tcp.h>
48 #include "interface.h"
49 #include "addrtoname.h"
51 #include <netinet/ip6.h>
54 * print an IP6 datagram.
57 ip6_print(register const u_char
*bp
, register int length
)
59 register const struct ip6_hdr
*ip6
;
62 register const u_char
*cp
;
66 ip6
= (const struct ip6_hdr
*)bp
;
70 * The IP header is not word aligned, so copy into abuf.
71 * This will never happen with BPF. It does happen raw packet
74 if ((int)ip
& (sizeof(long)-1)) {
78 abuf
= (u_char
*)malloc(snaplen
);
79 bcopy((char *)ip
, (char *)abuf
, min(length
, snaplen
));
80 snapend
+= abuf
- (u_char
*)ip
;
82 ip
= (struct ip6_hdr
*)abuf
;
85 if ((u_char
*)(ip6
+ 1) > snapend
) {
89 if (length
< sizeof (struct ip6_hdr
)) {
90 (void)printf("truncated-ip6 %d", length
);
93 hlen
= sizeof(struct ip6_hdr
);
95 len
= ntohs(ip6
->ip6_plen
);
96 if (length
< len
+ hlen
)
97 (void)printf("truncated-ip6 - %d bytes missing!",
100 cp
= (const u_char
*)ip6
;
102 while (cp
< snapend
) {
105 if (cp
== (u_char
*)(ip6
+ 1)
106 && nh
!= IPPROTO_TCP
&& nh
!= IPPROTO_UDP
) {
107 (void)printf("%s > %s: ", ip6addr_string(&ip6
->ip6_src
),
108 ip6addr_string(&ip6
->ip6_dst
));
112 case IPPROTO_HOPOPTS
:
113 hlen
= hbhopt_print(cp
);
116 case IPPROTO_DSTOPTS
:
117 hlen
= dstopt_print(cp
);
120 case IPPROTO_FRAGMENT
:
121 hlen
= frag6_print(cp
, (const u_char
*)ip6
);
122 if (snapend
<= cp
+ hlen
)
126 case IPPROTO_ROUTING
:
127 hlen
= rt6_print(cp
, (const u_char
*)ip6
);
131 tcp_print(cp
, len
+ sizeof(struct ip6_hdr
) - (cp
- bp
),
132 (const u_char
*)ip6
);
135 udp_print(cp
, len
+ sizeof(struct ip6_hdr
) - (cp
- bp
),
136 (const u_char
*)ip6
);
139 icmp6_print(cp
, (const u_char
*)ip6
);
142 hlen
= ah_print(cp
, (const u_char
*)ip6
);
148 cp
+= esp_print(cp
, (const u_char
*)ip6
, &enh
);
154 #ifndef IPPROTO_IPCOMP
155 #define IPPROTO_IPCOMP 108
160 cp
+= ipcomp_print(cp
, (const u_char
*)ip6
, &enh
);
171 #define IPPROTO_OSPF 89
174 ospf6_print(cp
, len
);
180 #define IPPROTO_IPV4 4
186 (void)printf("no next header");
190 (void)printf("ip-proto-%d %d", ip6
->ip6_nxt
, len
);
197 flow
= ntohl(ip6
->ip6_flow
);
200 if (flow
& 0x0f000000)
201 (void)printf(" [pri 0x%x]", (flow
& 0x0f000000) >> 24);
202 if (flow
& 0x00ffffff)
203 (void)printf(" [flowlabel 0x%x]", flow
& 0x00ffffff);
206 if (flow
& 0x0ff00000)
207 (void)printf(" [class 0x%x]", (flow
& 0x0ff00000) >> 20);
208 if (flow
& 0x000fffff)
209 (void)printf(" [flowlabel 0x%x]", flow
& 0x000fffff);
212 if (ip6
->ip6_hlim
<= 1)
213 (void)printf(" [hlim %d]", (int)ip6
->ip6_hlim
);
217 (void)printf("len %d", len
);
218 if (ip6
->ip6_hlim
> 1)
219 (void)printf(", hlim %d", (int)ip6
->ip6_hlim
);