xref: /freebsd/contrib/tcpdump/print-cip.c (revision 0a7e5f1f02aad2ff5fff1c60f44c6975fd07e1d9)
1b0453382SBill Fenner /*
2b0453382SBill Fenner  * Marko Kiiskila carnil@cs.tut.fi
3b0453382SBill Fenner  *
4b0453382SBill Fenner  * Tampere University of Technology - Telecommunications Laboratory
5b0453382SBill Fenner  *
6b0453382SBill Fenner  * Permission to use, copy, modify and distribute this
7b0453382SBill Fenner  * software and its documentation is hereby granted,
8b0453382SBill Fenner  * provided that both the copyright notice and this
9b0453382SBill Fenner  * permission notice appear in all copies of the software,
10b0453382SBill Fenner  * derivative works or modified versions, and any portions
11b0453382SBill Fenner  * thereof, that both notices appear in supporting
12b0453382SBill Fenner  * documentation, and that the use of this software is
13b0453382SBill Fenner  * acknowledged in any publications resulting from using
14b0453382SBill Fenner  * the software.
15b0453382SBill Fenner  *
16b0453382SBill Fenner  * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17b0453382SBill Fenner  * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR
18b0453382SBill Fenner  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS
19b0453382SBill Fenner  * SOFTWARE.
20b0453382SBill Fenner  *
21b0453382SBill Fenner  */
22b0453382SBill Fenner 
23*ee67461eSJoseph Mingrone /* \summary: Linux Classical IP over ATM printer */
243340d773SGleb Smirnoff 
25*ee67461eSJoseph Mingrone #include <config.h>
26b0453382SBill Fenner 
27a90e161bSBill Fenner #include <string.h>
28a90e161bSBill Fenner 
29*ee67461eSJoseph Mingrone #include "netdissect-stdinc.h"
30b0453382SBill Fenner 
31*ee67461eSJoseph Mingrone #define ND_LONGJMP_FROM_TCHECK
323340d773SGleb Smirnoff #include "netdissect.h"
33b0453382SBill Fenner #include "addrtoname.h"
34b0453382SBill Fenner 
353c602fabSXin LI static const unsigned char rfcllc[] = {
36b0453382SBill Fenner 	0xaa,	/* DSAP: non-ISO */
37b0453382SBill Fenner 	0xaa,	/* SSAP: non-ISO */
38b0453382SBill Fenner 	0x03,	/* Ctrl: Unnumbered Information Command PDU */
39b0453382SBill Fenner 	0x00,	/* OUI: EtherType */
40b0453382SBill Fenner 	0x00,
41b0453382SBill Fenner 	0x00 };
42b0453382SBill Fenner 
43b0453382SBill Fenner /*
445b0fe478SBruce M Simpson  * This is the top level routine of the printer.  'p' points
455b0fe478SBruce M Simpson  * to the LLC/SNAP or raw header of the packet, 'h->ts' is the timestamp,
461de50e9fSSam Leffler  * 'h->len' is the length of the packet off the wire, and 'h->caplen'
47b0453382SBill Fenner  * is the number of bytes actually captured.
48b0453382SBill Fenner  */
49*ee67461eSJoseph Mingrone void
cip_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)503c602fabSXin LI cip_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
51b0453382SBill Fenner {
52a90e161bSBill Fenner 	u_int caplen = h->caplen;
53a90e161bSBill Fenner 	u_int length = h->len;
543340d773SGleb Smirnoff 	int llc_hdrlen;
55b0453382SBill Fenner 
56*ee67461eSJoseph Mingrone 	ndo->ndo_protocol = "cip";
57b0453382SBill Fenner 
583c602fabSXin LI 	if (ndo->ndo_eflag)
59*ee67461eSJoseph Mingrone 		/*
60*ee67461eSJoseph Mingrone 		 * There is no MAC-layer header, so just print the length.
61*ee67461eSJoseph Mingrone 		 */
62*ee67461eSJoseph Mingrone 		ND_PRINT("%u: ", length);
63b0453382SBill Fenner 
64*ee67461eSJoseph Mingrone 	ND_TCHECK_LEN(p, sizeof(rfcllc));
65*ee67461eSJoseph Mingrone 	if (memcmp(rfcllc, p, sizeof(rfcllc)) == 0) {
66b0453382SBill Fenner 		/*
67a90e161bSBill Fenner 		 * LLC header is present.  Try to print it & higher layers.
68b0453382SBill Fenner 		 */
693340d773SGleb Smirnoff 		llc_hdrlen = llc_print(ndo, p, length, caplen, NULL, NULL);
703340d773SGleb Smirnoff 		if (llc_hdrlen < 0) {
713340d773SGleb Smirnoff 			/* packet type not known, print raw packet */
723c602fabSXin LI 			if (!ndo->ndo_suppress_default_print)
733c602fabSXin LI 				ND_DEFAULTPRINT(p, caplen);
743340d773SGleb Smirnoff 			llc_hdrlen = -llc_hdrlen;
75b0453382SBill Fenner 		}
76a90e161bSBill Fenner 	} else {
77a90e161bSBill Fenner 		/*
78a90e161bSBill Fenner 		 * LLC header is absent; treat it as just IP.
79a90e161bSBill Fenner 		 */
803340d773SGleb Smirnoff 		llc_hdrlen = 0;
813c602fabSXin LI 		ip_print(ndo, p, length);
82b0453382SBill Fenner 	}
83a90e161bSBill Fenner 
84*ee67461eSJoseph Mingrone 	ndo->ndo_ll_hdr_len += llc_hdrlen;
85b0453382SBill Fenner }
86