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.8 2024/09/02 16:15:30 christos Exp $");
26 #endif
27
28 /* \summary: Linux Classical IP over ATM printer */
29
30 #include <config.h>
31
32 #include <string.h>
33
34 #include "netdissect-stdinc.h"
35
36 #define ND_LONGJMP_FROM_TCHECK
37 #include "netdissect.h"
38 #include "addrtoname.h"
39
40 static const unsigned char rfcllc[] = {
41 0xaa, /* DSAP: non-ISO */
42 0xaa, /* SSAP: non-ISO */
43 0x03, /* Ctrl: Unnumbered Information Command PDU */
44 0x00, /* OUI: EtherType */
45 0x00,
46 0x00 };
47
48 /*
49 * This is the top level routine of the printer. 'p' points
50 * to the LLC/SNAP or raw header of the packet, 'h->ts' is the timestamp,
51 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
52 * is the number of bytes actually captured.
53 */
54 void
cip_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)55 cip_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
56 {
57 u_int caplen = h->caplen;
58 u_int length = h->len;
59 int llc_hdrlen;
60
61 ndo->ndo_protocol = "cip";
62
63 if (ndo->ndo_eflag)
64 /*
65 * There is no MAC-layer header, so just print the length.
66 */
67 ND_PRINT("%u: ", length);
68
69 ND_TCHECK_LEN(p, sizeof(rfcllc));
70 if (memcmp(rfcllc, p, sizeof(rfcllc)) == 0) {
71 /*
72 * LLC header is present. Try to print it & higher layers.
73 */
74 llc_hdrlen = llc_print(ndo, p, length, caplen, NULL, NULL);
75 if (llc_hdrlen < 0) {
76 /* packet type not known, print raw packet */
77 if (!ndo->ndo_suppress_default_print)
78 ND_DEFAULTPRINT(p, caplen);
79 llc_hdrlen = -llc_hdrlen;
80 }
81 } else {
82 /*
83 * LLC header is absent; treat it as just IP.
84 */
85 llc_hdrlen = 0;
86 ip_print(ndo, p, length);
87 }
88
89 ndo->ndo_ll_hdr_len += llc_hdrlen;
90 }
91