xref: /aosp_15_r20/external/tcpdump/print-sunatm.c (revision 05b00f6010a2396e3db2409989fc67270046269f)
1*05b00f60SXin Li /*
2*05b00f60SXin Li  * Copyright (c) 1997 Yen Yen Lim and North Dakota State University
3*05b00f60SXin Li  * 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 the following conditions
7*05b00f60SXin Li  * are met:
8*05b00f60SXin Li  * 1. Redistributions of source code must retain the above copyright
9*05b00f60SXin Li  *    notice, this list of conditions and the following disclaimer.
10*05b00f60SXin Li  * 2. Redistributions in binary form must reproduce the above copyright
11*05b00f60SXin Li  *    notice, this list of conditions and the following disclaimer in the
12*05b00f60SXin Li  *    documentation and/or other materials provided with the distribution.
13*05b00f60SXin Li  * 3. All advertising materials mentioning features or use of this software
14*05b00f60SXin Li  *    must display the following acknowledgement:
15*05b00f60SXin Li  *      This product includes software developed by Yen Yen Lim and
16*05b00f60SXin Li 	North Dakota State University
17*05b00f60SXin Li  * 4. The name of the author may not be used to endorse or promote products
18*05b00f60SXin Li  *    derived from this software without specific prior written permission.
19*05b00f60SXin Li  *
20*05b00f60SXin Li  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21*05b00f60SXin Li  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22*05b00f60SXin Li  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23*05b00f60SXin Li  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24*05b00f60SXin Li  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25*05b00f60SXin Li  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26*05b00f60SXin Li  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27*05b00f60SXin Li  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28*05b00f60SXin Li  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29*05b00f60SXin Li  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30*05b00f60SXin Li  * POSSIBILITY OF SUCH DAMAGE.
31*05b00f60SXin Li  */
32*05b00f60SXin Li 
33*05b00f60SXin Li /* \summary: SunATM DLPI capture printer */
34*05b00f60SXin Li 
35*05b00f60SXin Li #ifdef HAVE_CONFIG_H
36*05b00f60SXin Li #include <config.h>
37*05b00f60SXin Li #endif
38*05b00f60SXin Li 
39*05b00f60SXin Li #include "netdissect-stdinc.h"
40*05b00f60SXin Li 
41*05b00f60SXin Li #define ND_LONGJMP_FROM_TCHECK
42*05b00f60SXin Li #include "netdissect.h"
43*05b00f60SXin Li #include "extract.h"
44*05b00f60SXin Li 
45*05b00f60SXin Li #include "atm.h"
46*05b00f60SXin Li 
47*05b00f60SXin Li /* SunATM header for ATM packet */
48*05b00f60SXin Li #define DIR_POS		0	/* Direction (0x80 = transmit, 0x00 = receive) */
49*05b00f60SXin Li #define VPI_POS		1	/* VPI */
50*05b00f60SXin Li #define VCI_POS		2	/* VCI */
51*05b00f60SXin Li #define PKT_BEGIN_POS   4	/* Start of the ATM packet */
52*05b00f60SXin Li 
53*05b00f60SXin Li /* Protocol type values in the bottom for bits of the byte at SUNATM_DIR_POS. */
54*05b00f60SXin Li #define PT_LANE		0x01	/* LANE */
55*05b00f60SXin Li #define PT_LLC		0x02	/* LLC encapsulation */
56*05b00f60SXin Li 
57*05b00f60SXin Li /*
58*05b00f60SXin Li  * This is the top level routine of the printer.  'p' points
59*05b00f60SXin Li  * to the SunATM pseudo-header for the packet, 'h->ts' is the timestamp,
60*05b00f60SXin Li  * 'h->len' is the length of the packet off the wire, and 'h->caplen'
61*05b00f60SXin Li  * is the number of bytes actually captured.
62*05b00f60SXin Li  */
63*05b00f60SXin Li void
sunatm_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)64*05b00f60SXin Li sunatm_if_print(netdissect_options *ndo,
65*05b00f60SXin Li                 const struct pcap_pkthdr *h, const u_char *p)
66*05b00f60SXin Li {
67*05b00f60SXin Li 	u_int caplen = h->caplen;
68*05b00f60SXin Li 	u_int length = h->len;
69*05b00f60SXin Li 	u_short vci;
70*05b00f60SXin Li 	u_char vpi;
71*05b00f60SXin Li 	u_int traftype;
72*05b00f60SXin Li 
73*05b00f60SXin Li 	ndo->ndo_protocol = "sunatm";
74*05b00f60SXin Li 
75*05b00f60SXin Li 	if (ndo->ndo_eflag) {
76*05b00f60SXin Li 		ND_PRINT(GET_U_1(p + DIR_POS) & 0x80 ? "Tx: " : "Rx: ");
77*05b00f60SXin Li 	}
78*05b00f60SXin Li 
79*05b00f60SXin Li 	switch (GET_U_1(p + DIR_POS) & 0x0f) {
80*05b00f60SXin Li 
81*05b00f60SXin Li 	case PT_LANE:
82*05b00f60SXin Li 		traftype = ATM_LANE;
83*05b00f60SXin Li 		break;
84*05b00f60SXin Li 
85*05b00f60SXin Li 	case PT_LLC:
86*05b00f60SXin Li 		traftype = ATM_LLC;
87*05b00f60SXin Li 		break;
88*05b00f60SXin Li 
89*05b00f60SXin Li 	default:
90*05b00f60SXin Li 		traftype = ATM_UNKNOWN;
91*05b00f60SXin Li 		break;
92*05b00f60SXin Li 	}
93*05b00f60SXin Li 
94*05b00f60SXin Li 	vpi = GET_U_1(p + VPI_POS);
95*05b00f60SXin Li 	vci = GET_BE_U_2(p + VCI_POS);
96*05b00f60SXin Li 
97*05b00f60SXin Li 	p += PKT_BEGIN_POS;
98*05b00f60SXin Li 	caplen -= PKT_BEGIN_POS;
99*05b00f60SXin Li 	length -= PKT_BEGIN_POS;
100*05b00f60SXin Li 	ndo->ndo_ll_hdr_len += PKT_BEGIN_POS;
101*05b00f60SXin Li 	atm_print(ndo, vpi, vci, traftype, p, length, caplen);
102*05b00f60SXin Li }
103