xref: /freebsd/contrib/tcpdump/print-frag6.c (revision b0453382235492c8e30b09659b52d784128ca7d0)
1b0453382SBill Fenner /*
2b0453382SBill Fenner  * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994
3b0453382SBill Fenner  *	The Regents of the University of California.  All rights reserved.
4b0453382SBill Fenner  *
5b0453382SBill Fenner  * Redistribution and use in source and binary forms, with or without
6b0453382SBill Fenner  * modification, are permitted provided that: (1) source code distributions
7b0453382SBill Fenner  * retain the above copyright notice and this paragraph in its entirety, (2)
8b0453382SBill Fenner  * distributions including binary code include the above copyright notice and
9b0453382SBill Fenner  * this paragraph in its entirety in the documentation or other materials
10b0453382SBill Fenner  * provided with the distribution, and (3) all advertising materials mentioning
11b0453382SBill Fenner  * features or use of this software display the following acknowledgement:
12b0453382SBill Fenner  * ``This product includes software developed by the University of California,
13b0453382SBill Fenner  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14b0453382SBill Fenner  * the University nor the names of its contributors may be used to endorse
15b0453382SBill Fenner  * or promote products derived from this software without specific prior
16b0453382SBill Fenner  * written permission.
17b0453382SBill Fenner  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18b0453382SBill Fenner  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19b0453382SBill Fenner  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20b0453382SBill Fenner  */
21b0453382SBill Fenner 
22b0453382SBill Fenner #ifndef lint
23b0453382SBill Fenner static const char rcsid[] =
24b0453382SBill Fenner     "@(#) $Header: /tcpdump/master/tcpdump/print-frag6.c,v 1.3.2.1 2000/01/11 06:58:24 fenner Exp $";
25b0453382SBill Fenner #endif
26b0453382SBill Fenner 
27b0453382SBill Fenner #ifdef HAVE_CONFIG_H
28b0453382SBill Fenner #include "config.h"
29b0453382SBill Fenner #endif
30b0453382SBill Fenner 
31b0453382SBill Fenner #ifdef INET6
32b0453382SBill Fenner 
33b0453382SBill Fenner #include <sys/param.h>
34b0453382SBill Fenner #include <sys/time.h>
35b0453382SBill Fenner #include <sys/types.h>
36b0453382SBill Fenner #include <sys/socket.h>
37b0453382SBill Fenner 
38b0453382SBill Fenner #include <net/if.h>
39b0453382SBill Fenner 
40b0453382SBill Fenner #include <netinet/in.h>
41b0453382SBill Fenner #include <netinet/if_ether.h>
42b0453382SBill Fenner #include <netinet/in_systm.h>
43b0453382SBill Fenner #include <netinet/ip.h>
44b0453382SBill Fenner #include <netinet/ip_icmp.h>
45b0453382SBill Fenner #include <netinet/ip_var.h>
46b0453382SBill Fenner #include <netinet/udp.h>
47b0453382SBill Fenner #include <netinet/udp_var.h>
48b0453382SBill Fenner #include <netinet/tcp.h>
49b0453382SBill Fenner 
50b0453382SBill Fenner #include <stdio.h>
51b0453382SBill Fenner 
52b0453382SBill Fenner #include <netinet/ip6.h>
53b0453382SBill Fenner 
54b0453382SBill Fenner #include "interface.h"
55b0453382SBill Fenner #include "addrtoname.h"
56b0453382SBill Fenner 
57b0453382SBill Fenner int
58b0453382SBill Fenner frag6_print(register const u_char *bp, register const u_char *bp2)
59b0453382SBill Fenner {
60b0453382SBill Fenner 	register const struct ip6_frag *dp;
61b0453382SBill Fenner 	register const struct ip6_hdr *ip6;
62b0453382SBill Fenner 	register const u_char *ep;
63b0453382SBill Fenner 
64b0453382SBill Fenner #if 0
65b0453382SBill Fenner #define TCHECK(var) if ((u_char *)&(var) >= ep - sizeof(var)) goto trunc
66b0453382SBill Fenner #endif
67b0453382SBill Fenner 
68b0453382SBill Fenner 	dp = (struct ip6_frag *)bp;
69b0453382SBill Fenner 	ip6 = (struct ip6_hdr *)bp2;
70b0453382SBill Fenner 
71b0453382SBill Fenner 	/* 'ep' points to the end of avaible data. */
72b0453382SBill Fenner 	ep = snapend;
73b0453382SBill Fenner 
74b0453382SBill Fenner 	TCHECK(dp->ip6f_offlg);
75b0453382SBill Fenner 
76b0453382SBill Fenner 	if (vflag) {
77b0453382SBill Fenner 		printf("frag (0x%08x:%d|%ld)",
78b0453382SBill Fenner 		       (u_int32_t)ntohl(dp->ip6f_ident),
79b0453382SBill Fenner 		       ntohs(dp->ip6f_offlg & IP6F_OFF_MASK),
80b0453382SBill Fenner 		       sizeof(struct ip6_hdr) + ntohs(ip6->ip6_plen) -
81b0453382SBill Fenner 			       (long)(bp - bp2) - sizeof(struct ip6_frag));
82b0453382SBill Fenner 	} else {
83b0453382SBill Fenner 		printf("frag (%d|%ld)",
84b0453382SBill Fenner 		       ntohs(dp->ip6f_offlg & IP6F_OFF_MASK),
85b0453382SBill Fenner 		       sizeof(struct ip6_hdr) + ntohs(ip6->ip6_plen) -
86b0453382SBill Fenner 			       (long)(bp - bp2) - sizeof(struct ip6_frag));
87b0453382SBill Fenner 	}
88b0453382SBill Fenner 
89b0453382SBill Fenner #if 0
90b0453382SBill Fenner 	/* it is meaningless to decode non-first fragment */
91b0453382SBill Fenner 	if (ntohs(dp->ip6f_offlg & IP6F_OFF_MASK) != 0)
92b0453382SBill Fenner 		return 65535;
93b0453382SBill Fenner 	else
94b0453382SBill Fenner #endif
95b0453382SBill Fenner 	{
96b0453382SBill Fenner 		fputs(" ", stdout);
97b0453382SBill Fenner 		return sizeof(struct ip6_frag);
98b0453382SBill Fenner 	}
99b0453382SBill Fenner trunc:
100b0453382SBill Fenner 	fputs("[|frag]", stdout);
101b0453382SBill Fenner 	return 65535;
102b0453382SBill Fenner #undef TCHECK
103b0453382SBill Fenner }
104b0453382SBill Fenner #endif /* INET6 */
105