xref: /minix/external/bsd/tcpdump/dist/print-cip.c (revision b636d99d)
1 /*
2  * Marko Kiiskila carnil@cs.tut.fi
3  *
4  * Tampere University of Technology - Telecommunications Laboratory
5  *
6  * Permission to use, copy, modify and distribute this
7  * software and its documentation is hereby granted,
8  * provided that both the copyright notice and this
9  * permission notice appear in all copies of the software,
10  * derivative works or modified versions, and any portions
11  * thereof, that both notices appear in supporting
12  * documentation, and that the use of this software is
13  * acknowledged in any publications resulting from using
14  * the software.
15  *
16  * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17  * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR
18  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS
19  * SOFTWARE.
20  *
21  */
22 
23 #include <sys/cdefs.h>
24 #ifndef lint
25 __RCSID("$NetBSD: print-cip.c,v 1.4 2014/11/20 03:05:03 christos Exp $");
26 #endif
27 
28 #define NETDISSECT_REWORKED
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32 
33 #include <string.h>
34 
35 #include <tcpdump-stdinc.h>
36 
37 #include "interface.h"
38 #include "addrtoname.h"
39 
40 #define RFC1483LLC_LEN	8
41 
42 static const unsigned char rfcllc[] = {
43 	0xaa,	/* DSAP: non-ISO */
44 	0xaa,	/* SSAP: non-ISO */
45 	0x03,	/* Ctrl: Unnumbered Information Command PDU */
46 	0x00,	/* OUI: EtherType */
47 	0x00,
48 	0x00 };
49 
50 static inline void
cip_print(netdissect_options * ndo,int length)51 cip_print(netdissect_options *ndo, int length)
52 {
53 	/*
54 	 * There is no MAC-layer header, so just print the length.
55 	 */
56 	ND_PRINT((ndo, "%d: ", length));
57 }
58 
59 /*
60  * This is the top level routine of the printer.  'p' points
61  * to the LLC/SNAP or raw header of the packet, 'h->ts' is the timestamp,
62  * 'h->len' is the length of the packet off the wire, and 'h->caplen'
63  * is the number of bytes actually captured.
64  */
65 u_int
cip_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)66 cip_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
67 {
68 	u_int caplen = h->caplen;
69 	u_int length = h->len;
70 	u_short extracted_ethertype;
71 
72 	if (memcmp(rfcllc, p, sizeof(rfcllc))==0 && caplen < RFC1483LLC_LEN) {
73 		ND_PRINT((ndo, "[|cip]"));
74 		return (0);
75 	}
76 
77 	if (ndo->ndo_eflag)
78 		cip_print(ndo, length);
79 
80 	if (memcmp(rfcllc, p, sizeof(rfcllc)) == 0) {
81 		/*
82 		 * LLC header is present.  Try to print it & higher layers.
83 		 */
84 		if (llc_print(ndo, p, length, caplen, NULL, NULL,
85 		    &extracted_ethertype) == 0) {
86 			/* ether_type not known, print raw packet */
87 			if (!ndo->ndo_eflag)
88 				cip_print(ndo, length);
89 			if (extracted_ethertype) {
90 				ND_PRINT((ndo, "(LLC %s) ",
91 			       etherproto_string(htons(extracted_ethertype))));
92 			}
93 			if (!ndo->ndo_suppress_default_print)
94 				ND_DEFAULTPRINT(p, caplen);
95 		}
96 	} else {
97 		/*
98 		 * LLC header is absent; treat it as just IP.
99 		 */
100 		ip_print(ndo, p, length);
101 	}
102 
103 	return (0);
104 }
105 
106 
107 /*
108  * Local Variables:
109  * c-style: whitesmith
110  * c-basic-offset: 8
111  * End:
112  */
113