blob: b8ef77fd2fb3ab80407a5292fafdb42417f189e4 [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
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
Elliott Hughes820eced2021-08-20 18:00:50 -070023/* \summary: Linux Classical IP over ATM printer */
Elliott Hughese2e3bd12017-05-15 10:59:29 -070024
The Android Open Source Project2949f582009-03-03 19:30:46 -080025#ifdef HAVE_CONFIG_H
Elliott Hughes820eced2021-08-20 18:00:50 -070026#include <config.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080027#endif
28
29#include <string.h>
30
Elliott Hughes820eced2021-08-20 18:00:50 -070031#include "netdissect-stdinc.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080032
Elliott Hughes820eced2021-08-20 18:00:50 -070033#define ND_LONGJMP_FROM_TCHECK
Elliott Hughese2e3bd12017-05-15 10:59:29 -070034#include "netdissect.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080035#include "addrtoname.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080036
Elliott Hughes892a68b2015-10-19 14:43:53 -070037static const unsigned char rfcllc[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080038 0xaa, /* DSAP: non-ISO */
39 0xaa, /* SSAP: non-ISO */
40 0x03, /* Ctrl: Unnumbered Information Command PDU */
41 0x00, /* OUI: EtherType */
42 0x00,
43 0x00 };
44
The Android Open Source Project2949f582009-03-03 19:30:46 -080045/*
46 * This is the top level routine of the printer. 'p' points
47 * to the LLC/SNAP or raw header of the packet, 'h->ts' is the timestamp,
48 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
49 * is the number of bytes actually captured.
50 */
Elliott Hughes820eced2021-08-20 18:00:50 -070051void
Elliott Hughes892a68b2015-10-19 14:43:53 -070052cip_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -080053{
54 u_int caplen = h->caplen;
55 u_int length = h->len;
Elliott Hughese2e3bd12017-05-15 10:59:29 -070056 int llc_hdrlen;
The Android Open Source Project2949f582009-03-03 19:30:46 -080057
Elliott Hughes820eced2021-08-20 18:00:50 -070058 ndo->ndo_protocol = "cip";
The Android Open Source Project2949f582009-03-03 19:30:46 -080059
Elliott Hughes892a68b2015-10-19 14:43:53 -070060 if (ndo->ndo_eflag)
Elliott Hughes820eced2021-08-20 18:00:50 -070061 /*
62 * There is no MAC-layer header, so just print the length.
63 */
64 ND_PRINT("%u: ", length);
The Android Open Source Project2949f582009-03-03 19:30:46 -080065
Elliott Hughes820eced2021-08-20 18:00:50 -070066 ND_TCHECK_LEN(p, sizeof(rfcllc));
67 if (memcmp(rfcllc, p, sizeof(rfcllc)) == 0) {
The Android Open Source Project2949f582009-03-03 19:30:46 -080068 /*
69 * LLC header is present. Try to print it & higher layers.
70 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -070071 llc_hdrlen = llc_print(ndo, p, length, caplen, NULL, NULL);
72 if (llc_hdrlen < 0) {
73 /* packet type not known, print raw packet */
Elliott Hughes892a68b2015-10-19 14:43:53 -070074 if (!ndo->ndo_suppress_default_print)
75 ND_DEFAULTPRINT(p, caplen);
Elliott Hughese2e3bd12017-05-15 10:59:29 -070076 llc_hdrlen = -llc_hdrlen;
The Android Open Source Project2949f582009-03-03 19:30:46 -080077 }
78 } else {
79 /*
80 * LLC header is absent; treat it as just IP.
81 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -070082 llc_hdrlen = 0;
Elliott Hughes892a68b2015-10-19 14:43:53 -070083 ip_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -080084 }
85
Elliott Hughes820eced2021-08-20 18:00:50 -070086 ndo->ndo_ll_hdr_len += llc_hdrlen;
The Android Open Source Project2949f582009-03-03 19:30:46 -080087}