xref: /aosp_15_r20/external/tcpdump/print-frag6.c (revision 05b00f6010a2396e3db2409989fc67270046269f)
1*05b00f60SXin Li /*
2*05b00f60SXin Li  * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994
3*05b00f60SXin Li  *	The Regents of the University of California.  All rights reserved.
4*05b00f60SXin Li  *
5*05b00f60SXin Li  * Redistribution and use in source and binary forms, with or without
6*05b00f60SXin Li  * modification, are permitted provided that: (1) source code distributions
7*05b00f60SXin Li  * retain the above copyright notice and this paragraph in its entirety, (2)
8*05b00f60SXin Li  * distributions including binary code include the above copyright notice and
9*05b00f60SXin Li  * this paragraph in its entirety in the documentation or other materials
10*05b00f60SXin Li  * provided with the distribution, and (3) all advertising materials mentioning
11*05b00f60SXin Li  * features or use of this software display the following acknowledgement:
12*05b00f60SXin Li  * ``This product includes software developed by the University of California,
13*05b00f60SXin Li  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14*05b00f60SXin Li  * the University nor the names of its contributors may be used to endorse
15*05b00f60SXin Li  * or promote products derived from this software without specific prior
16*05b00f60SXin Li  * written permission.
17*05b00f60SXin Li  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18*05b00f60SXin Li  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19*05b00f60SXin Li  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20*05b00f60SXin Li  */
21*05b00f60SXin Li 
22*05b00f60SXin Li /* \summary: IPv6 fragmentation header printer */
23*05b00f60SXin Li 
24*05b00f60SXin Li #ifdef HAVE_CONFIG_H
25*05b00f60SXin Li #include <config.h>
26*05b00f60SXin Li #endif
27*05b00f60SXin Li 
28*05b00f60SXin Li #include "netdissect-stdinc.h"
29*05b00f60SXin Li 
30*05b00f60SXin Li #include "netdissect.h"
31*05b00f60SXin Li #include "extract.h"
32*05b00f60SXin Li 
33*05b00f60SXin Li #include "ip6.h"
34*05b00f60SXin Li 
35*05b00f60SXin Li int
frag6_print(netdissect_options * ndo,const u_char * bp,const u_char * bp2)36*05b00f60SXin Li frag6_print(netdissect_options *ndo, const u_char *bp, const u_char *bp2)
37*05b00f60SXin Li {
38*05b00f60SXin Li 	const struct ip6_frag *dp;
39*05b00f60SXin Li 	const struct ip6_hdr *ip6;
40*05b00f60SXin Li 
41*05b00f60SXin Li 	ndo->ndo_protocol = "frag6";
42*05b00f60SXin Li 	dp = (const struct ip6_frag *)bp;
43*05b00f60SXin Li 	ip6 = (const struct ip6_hdr *)bp2;
44*05b00f60SXin Li 
45*05b00f60SXin Li 	if (ndo->ndo_vflag) {
46*05b00f60SXin Li 		ND_PRINT("frag (0x%08x:%u|%zu)",
47*05b00f60SXin Li 			 GET_BE_U_4(dp->ip6f_ident),
48*05b00f60SXin Li 			 GET_BE_U_2(dp->ip6f_offlg) & IP6F_OFF_MASK,
49*05b00f60SXin Li 			 sizeof(struct ip6_hdr) + GET_BE_U_2(ip6->ip6_plen) -
50*05b00f60SXin Li 			        (bp - bp2) - sizeof(struct ip6_frag));
51*05b00f60SXin Li 	} else {
52*05b00f60SXin Li 		ND_PRINT("frag (%u|%zu)",
53*05b00f60SXin Li 		         GET_BE_U_2(dp->ip6f_offlg) & IP6F_OFF_MASK,
54*05b00f60SXin Li 		         sizeof(struct ip6_hdr) + GET_BE_U_2(ip6->ip6_plen) -
55*05b00f60SXin Li 			         (bp - bp2) - sizeof(struct ip6_frag));
56*05b00f60SXin Li 	}
57*05b00f60SXin Li 
58*05b00f60SXin Li 	/* it is meaningless to decode non-first fragment */
59*05b00f60SXin Li 	if ((GET_BE_U_2(dp->ip6f_offlg) & IP6F_OFF_MASK) != 0)
60*05b00f60SXin Li 		return -1;
61*05b00f60SXin Li 	else
62*05b00f60SXin Li 	{
63*05b00f60SXin Li 		ND_PRINT(" ");
64*05b00f60SXin Li 		return sizeof(struct ip6_frag);
65*05b00f60SXin Li 	}
66*05b00f60SXin Li }
67