xref: /freebsd/contrib/tcpdump/print-sunatm.c (revision 3340d77368116708ab5b5b95acf6c9c710528300)
15b0fe478SBruce M Simpson /*
25b0fe478SBruce M Simpson  * Copyright (c) 1997 Yen Yen Lim and North Dakota State University
35b0fe478SBruce M Simpson  * All rights reserved.
45b0fe478SBruce M Simpson  *
55b0fe478SBruce M Simpson  * Redistribution and use in source and binary forms, with or without
65b0fe478SBruce M Simpson  * modification, are permitted provided that the following conditions
75b0fe478SBruce M Simpson  * are met:
85b0fe478SBruce M Simpson  * 1. Redistributions of source code must retain the above copyright
95b0fe478SBruce M Simpson  *    notice, this list of conditions and the following disclaimer.
105b0fe478SBruce M Simpson  * 2. Redistributions in binary form must reproduce the above copyright
115b0fe478SBruce M Simpson  *    notice, this list of conditions and the following disclaimer in the
125b0fe478SBruce M Simpson  *    documentation and/or other materials provided with the distribution.
135b0fe478SBruce M Simpson  * 3. All advertising materials mentioning features or use of this software
145b0fe478SBruce M Simpson  *    must display the following acknowledgement:
155b0fe478SBruce M Simpson  *      This product includes software developed by Yen Yen Lim and
165b0fe478SBruce M Simpson 	North Dakota State University
175b0fe478SBruce M Simpson  * 4. The name of the author may not be used to endorse or promote products
185b0fe478SBruce M Simpson  *    derived from this software without specific prior written permission.
195b0fe478SBruce M Simpson  *
205b0fe478SBruce M Simpson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
215b0fe478SBruce M Simpson  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
225b0fe478SBruce M Simpson  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
235b0fe478SBruce M Simpson  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
245b0fe478SBruce M Simpson  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
255b0fe478SBruce M Simpson  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
265b0fe478SBruce M Simpson  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
275b0fe478SBruce M Simpson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
285b0fe478SBruce M Simpson  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
295b0fe478SBruce M Simpson  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
305b0fe478SBruce M Simpson  * POSSIBILITY OF SUCH DAMAGE.
315b0fe478SBruce M Simpson  */
325b0fe478SBruce M Simpson 
33*3340d773SGleb Smirnoff /* \summary: SunATM DLPI capture printer */
34*3340d773SGleb Smirnoff 
355b0fe478SBruce M Simpson #ifdef HAVE_CONFIG_H
365b0fe478SBruce M Simpson #include "config.h"
375b0fe478SBruce M Simpson #endif
385b0fe478SBruce M Simpson 
39*3340d773SGleb Smirnoff #include <netdissect-stdinc.h>
405b0fe478SBruce M Simpson 
415b0fe478SBruce M Simpson struct mbuf;
425b0fe478SBruce M Simpson struct rtentry;
435b0fe478SBruce M Simpson 
44*3340d773SGleb Smirnoff #include "netdissect.h"
455b0fe478SBruce M Simpson #include "extract.h"
465b0fe478SBruce M Simpson 
475b0fe478SBruce M Simpson #include "atm.h"
485b0fe478SBruce M Simpson 
495b0fe478SBruce M Simpson /* SunATM header for ATM packet */
505b0fe478SBruce M Simpson #define DIR_POS		0	/* Direction (0x80 = transmit, 0x00 = receive) */
515b0fe478SBruce M Simpson #define VPI_POS		1	/* VPI */
525b0fe478SBruce M Simpson #define VCI_POS		2	/* VCI */
535b0fe478SBruce M Simpson #define PKT_BEGIN_POS   4	/* Start of the ATM packet */
545b0fe478SBruce M Simpson 
555b0fe478SBruce M Simpson /* Protocol type values in the bottom for bits of the byte at SUNATM_DIR_POS. */
565b0fe478SBruce M Simpson #define PT_LANE		0x01	/* LANE */
575b0fe478SBruce M Simpson #define PT_LLC		0x02	/* LLC encapsulation */
585b0fe478SBruce M Simpson 
595b0fe478SBruce M Simpson /*
605b0fe478SBruce M Simpson  * This is the top level routine of the printer.  'p' points
615b0fe478SBruce M Simpson  * to the SunATM pseudo-header for the packet, 'h->ts' is the timestamp,
621de50e9fSSam Leffler  * 'h->len' is the length of the packet off the wire, and 'h->caplen'
635b0fe478SBruce M Simpson  * is the number of bytes actually captured.
645b0fe478SBruce M Simpson  */
655b0fe478SBruce M Simpson u_int
663c602fabSXin LI sunatm_if_print(netdissect_options *ndo,
673c602fabSXin LI                 const struct pcap_pkthdr *h, const u_char *p)
685b0fe478SBruce M Simpson {
695b0fe478SBruce M Simpson 	u_int caplen = h->caplen;
705b0fe478SBruce M Simpson 	u_int length = h->len;
715b0fe478SBruce M Simpson 	u_short vci;
725b0fe478SBruce M Simpson 	u_char vpi;
735b0fe478SBruce M Simpson 	u_int traftype;
745b0fe478SBruce M Simpson 
755b0fe478SBruce M Simpson 	if (caplen < PKT_BEGIN_POS) {
763c602fabSXin LI 		ND_PRINT((ndo, "[|atm]"));
775b0fe478SBruce M Simpson 		return (caplen);
785b0fe478SBruce M Simpson 	}
795b0fe478SBruce M Simpson 
803c602fabSXin LI 	if (ndo->ndo_eflag) {
813c602fabSXin LI 		ND_PRINT((ndo, p[DIR_POS] & 0x80 ? "Tx: " : "Rx: "));
825b0fe478SBruce M Simpson 	}
835b0fe478SBruce M Simpson 
845b0fe478SBruce M Simpson 	switch (p[DIR_POS] & 0x0f) {
855b0fe478SBruce M Simpson 
865b0fe478SBruce M Simpson 	case PT_LANE:
875b0fe478SBruce M Simpson 		traftype = ATM_LANE;
885b0fe478SBruce M Simpson 		break;
895b0fe478SBruce M Simpson 
905b0fe478SBruce M Simpson 	case PT_LLC:
915b0fe478SBruce M Simpson 		traftype = ATM_LLC;
925b0fe478SBruce M Simpson 		break;
935b0fe478SBruce M Simpson 
945b0fe478SBruce M Simpson 	default:
955b0fe478SBruce M Simpson 		traftype = ATM_UNKNOWN;
965b0fe478SBruce M Simpson 		break;
975b0fe478SBruce M Simpson 	}
985b0fe478SBruce M Simpson 
995b0fe478SBruce M Simpson 	vci = EXTRACT_16BITS(&p[VCI_POS]);
1005b0fe478SBruce M Simpson 	vpi = p[VPI_POS];
1015b0fe478SBruce M Simpson 
1025b0fe478SBruce M Simpson 	p += PKT_BEGIN_POS;
1035b0fe478SBruce M Simpson 	caplen -= PKT_BEGIN_POS;
1045b0fe478SBruce M Simpson 	length -= PKT_BEGIN_POS;
1053c602fabSXin LI 	atm_print(ndo, vpi, vci, traftype, p, length, caplen);
1065b0fe478SBruce M Simpson 
1075b0fe478SBruce M Simpson 	return (PKT_BEGIN_POS);
1085b0fe478SBruce M Simpson }
109