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