1*05b00f60SXin Li /*
2*05b00f60SXin Li * Marko Kiiskila [email protected]
3*05b00f60SXin Li *
4*05b00f60SXin Li * Tampere University of Technology - Telecommunications Laboratory
5*05b00f60SXin Li *
6*05b00f60SXin Li * Permission to use, copy, modify and distribute this
7*05b00f60SXin Li * software and its documentation is hereby granted,
8*05b00f60SXin Li * provided that both the copyright notice and this
9*05b00f60SXin Li * permission notice appear in all copies of the software,
10*05b00f60SXin Li * derivative works or modified versions, and any portions
11*05b00f60SXin Li * thereof, that both notices appear in supporting
12*05b00f60SXin Li * documentation, and that the use of this software is
13*05b00f60SXin Li * acknowledged in any publications resulting from using
14*05b00f60SXin Li * the software.
15*05b00f60SXin Li *
16*05b00f60SXin Li * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17*05b00f60SXin Li * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR
18*05b00f60SXin Li * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS
19*05b00f60SXin Li * SOFTWARE.
20*05b00f60SXin Li *
21*05b00f60SXin Li */
22*05b00f60SXin Li
23*05b00f60SXin Li /* \summary: Linux Classical IP over ATM printer */
24*05b00f60SXin Li
25*05b00f60SXin Li #ifdef HAVE_CONFIG_H
26*05b00f60SXin Li #include <config.h>
27*05b00f60SXin Li #endif
28*05b00f60SXin Li
29*05b00f60SXin Li #include <string.h>
30*05b00f60SXin Li
31*05b00f60SXin Li #include "netdissect-stdinc.h"
32*05b00f60SXin Li
33*05b00f60SXin Li #define ND_LONGJMP_FROM_TCHECK
34*05b00f60SXin Li #include "netdissect.h"
35*05b00f60SXin Li #include "addrtoname.h"
36*05b00f60SXin Li
37*05b00f60SXin Li static const unsigned char rfcllc[] = {
38*05b00f60SXin Li 0xaa, /* DSAP: non-ISO */
39*05b00f60SXin Li 0xaa, /* SSAP: non-ISO */
40*05b00f60SXin Li 0x03, /* Ctrl: Unnumbered Information Command PDU */
41*05b00f60SXin Li 0x00, /* OUI: EtherType */
42*05b00f60SXin Li 0x00,
43*05b00f60SXin Li 0x00 };
44*05b00f60SXin Li
45*05b00f60SXin Li /*
46*05b00f60SXin Li * This is the top level routine of the printer. 'p' points
47*05b00f60SXin Li * to the LLC/SNAP or raw header of the packet, 'h->ts' is the timestamp,
48*05b00f60SXin Li * 'h->len' is the length of the packet off the wire, and 'h->caplen'
49*05b00f60SXin Li * is the number of bytes actually captured.
50*05b00f60SXin Li */
51*05b00f60SXin Li void
cip_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)52*05b00f60SXin Li cip_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
53*05b00f60SXin Li {
54*05b00f60SXin Li u_int caplen = h->caplen;
55*05b00f60SXin Li u_int length = h->len;
56*05b00f60SXin Li int llc_hdrlen;
57*05b00f60SXin Li
58*05b00f60SXin Li ndo->ndo_protocol = "cip";
59*05b00f60SXin Li
60*05b00f60SXin Li if (ndo->ndo_eflag)
61*05b00f60SXin Li /*
62*05b00f60SXin Li * There is no MAC-layer header, so just print the length.
63*05b00f60SXin Li */
64*05b00f60SXin Li ND_PRINT("%u: ", length);
65*05b00f60SXin Li
66*05b00f60SXin Li ND_TCHECK_LEN(p, sizeof(rfcllc));
67*05b00f60SXin Li if (memcmp(rfcllc, p, sizeof(rfcllc)) == 0) {
68*05b00f60SXin Li /*
69*05b00f60SXin Li * LLC header is present. Try to print it & higher layers.
70*05b00f60SXin Li */
71*05b00f60SXin Li llc_hdrlen = llc_print(ndo, p, length, caplen, NULL, NULL);
72*05b00f60SXin Li if (llc_hdrlen < 0) {
73*05b00f60SXin Li /* packet type not known, print raw packet */
74*05b00f60SXin Li if (!ndo->ndo_suppress_default_print)
75*05b00f60SXin Li ND_DEFAULTPRINT(p, caplen);
76*05b00f60SXin Li llc_hdrlen = -llc_hdrlen;
77*05b00f60SXin Li }
78*05b00f60SXin Li } else {
79*05b00f60SXin Li /*
80*05b00f60SXin Li * LLC header is absent; treat it as just IP.
81*05b00f60SXin Li */
82*05b00f60SXin Li llc_hdrlen = 0;
83*05b00f60SXin Li ip_print(ndo, p, length);
84*05b00f60SXin Li }
85*05b00f60SXin Li
86*05b00f60SXin Li ndo->ndo_ll_hdr_len += llc_hdrlen;
87*05b00f60SXin Li }
88