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