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#if 0
26static const char rcsid[] _U_ =
27    "@(#) Header: /tcpdump/master/tcpdump/print-cip.c,v 1.26 2005-07-07 01:22:17 guy Exp (LBL)";
28#else
29__RCSID("$NetBSD$");
30#endif
31#endif
32
33#ifdef HAVE_CONFIG_H
34#include "config.h"
35#endif
36
37#include <string.h>
38
39#include <tcpdump-stdinc.h>
40
41#include <stdio.h>
42#include <pcap.h>
43
44#include "interface.h"
45#include "addrtoname.h"
46#include "ethertype.h"
47#include "ether.h"
48
49#define RFC1483LLC_LEN	8
50
51static unsigned char rfcllc[] = {
52	0xaa,	/* DSAP: non-ISO */
53	0xaa,	/* SSAP: non-ISO */
54	0x03,	/* Ctrl: Unnumbered Information Command PDU */
55	0x00,	/* OUI: EtherType */
56	0x00,
57	0x00 };
58
59static inline void
60cip_print(int length)
61{
62	/*
63	 * There is no MAC-layer header, so just print the length.
64	 */
65	printf("%d: ", length);
66}
67
68/*
69 * This is the top level routine of the printer.  'p' points
70 * to the LLC/SNAP or raw header of the packet, 'h->ts' is the timestamp,
71 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
72 * is the number of bytes actually captured.
73 */
74u_int
75cip_if_print(const struct pcap_pkthdr *h, const u_char *p)
76{
77	u_int caplen = h->caplen;
78	u_int length = h->len;
79	u_short extracted_ethertype;
80
81	if (memcmp(rfcllc, p, sizeof(rfcllc))==0 && caplen < RFC1483LLC_LEN) {
82		printf("[|cip]");
83		return (0);
84	}
85
86	if (eflag)
87		cip_print(length);
88
89	if (memcmp(rfcllc, p, sizeof(rfcllc)) == 0) {
90		/*
91		 * LLC header is present.  Try to print it & higher layers.
92		 */
93		if (llc_print(p, length, caplen, NULL, NULL,
94		    &extracted_ethertype) == 0) {
95			/* ether_type not known, print raw packet */
96			if (!eflag)
97				cip_print(length);
98			if (extracted_ethertype) {
99				printf("(LLC %s) ",
100			       etherproto_string(htons(extracted_ethertype)));
101			}
102			if (!suppress_default_print)
103				default_print(p, caplen);
104		}
105	} else {
106		/*
107		 * LLC header is absent; treat it as just IP.
108		 */
109		ip_print(gndo, p, length);
110	}
111
112	return (0);
113}
114
115
116/*
117 * Local Variables:
118 * c-style: whitesmith
119 * c-basic-offset: 8
120 * End:
121 */
122