1286441Srpaulo/*
2286441Srpaulo * Marko Kiiskila carnil@cs.tut.fi
3286441Srpaulo *
4286441Srpaulo * Tampere University of Technology - Telecommunications Laboratory
5286441Srpaulo *
6286441Srpaulo * Permission to use, copy, modify and distribute this
7286441Srpaulo * software and its documentation is hereby granted,
8286441Srpaulo * provided that both the copyright notice and this
9286441Srpaulo * permission notice appear in all copies of the software,
10286441Srpaulo * derivative works or modified versions, and any portions
11286441Srpaulo * thereof, that both notices appear in supporting
12286441Srpaulo * documentation, and that the use of this software is
13286441Srpaulo * acknowledged in any publications resulting from using
14286441Srpaulo * the software.
15286441Srpaulo *
16286441Srpaulo * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17286441Srpaulo * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR
18286441Srpaulo * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS
19286441Srpaulo * SOFTWARE.
20286441Srpaulo *
21286441Srpaulo */
22286441Srpaulo
23286441Srpaulo#ifndef lint
24286441Srpaulostatic const char rcsid[] _U_ =
25286441Srpaulo    "@(#) $Header: /tcpdump/master/tcpdump/print-cip.c,v 1.26 2005-07-07 01:22:17 guy Exp $ (LBL)";
26286441Srpaulo#endif
27286441Srpaulo
28286441Srpaulo#ifdef HAVE_CONFIG_H
29286441Srpaulo#include "config.h"
30286441Srpaulo#endif
31286441Srpaulo
32286441Srpaulo#include <string.h>
33286441Srpaulo
34286441Srpaulo#include <tcpdump-stdinc.h>
35286441Srpaulo
36286441Srpaulo#include <stdio.h>
37286441Srpaulo#include <pcap.h>
38286441Srpaulo
39286441Srpaulo#include "interface.h"
40286441Srpaulo#include "addrtoname.h"
41286441Srpaulo#include "ethertype.h"
42286441Srpaulo#include "ether.h"
43286441Srpaulo
44286441Srpaulo#define RFC1483LLC_LEN	8
45286441Srpaulo
46286441Srpaulostatic unsigned char rfcllc[] = {
47286441Srpaulo	0xaa,	/* DSAP: non-ISO */
48286441Srpaulo	0xaa,	/* SSAP: non-ISO */
49286441Srpaulo	0x03,	/* Ctrl: Unnumbered Information Command PDU */
50286441Srpaulo	0x00,	/* OUI: EtherType */
51286441Srpaulo	0x00,
52286441Srpaulo	0x00 };
53286441Srpaulo
54286441Srpaulostatic inline void
55286441Srpaulocip_print(int length)
56286441Srpaulo{
57286441Srpaulo	/*
58286441Srpaulo	 * There is no MAC-layer header, so just print the length.
59286441Srpaulo	 */
60286441Srpaulo	printf("%d: ", length);
61286441Srpaulo}
62286441Srpaulo
63286441Srpaulo/*
64286441Srpaulo * This is the top level routine of the printer.  'p' points
65286441Srpaulo * to the LLC/SNAP or raw header of the packet, 'h->ts' is the timestamp,
66286441Srpaulo * 'h->len' is the length of the packet off the wire, and 'h->caplen'
67286441Srpaulo * is the number of bytes actually captured.
68286441Srpaulo */
69286441Srpaulou_int
70286441Srpaulocip_if_print(const struct pcap_pkthdr *h, const u_char *p)
71286441Srpaulo{
72286441Srpaulo	u_int caplen = h->caplen;
73286441Srpaulo	u_int length = h->len;
74286441Srpaulo	u_short extracted_ethertype;
75286441Srpaulo
76286441Srpaulo	if (memcmp(rfcllc, p, sizeof(rfcllc))==0 && caplen < RFC1483LLC_LEN) {
77286441Srpaulo		printf("[|cip]");
78286441Srpaulo		return (0);
79286441Srpaulo	}
80286441Srpaulo
81286441Srpaulo	if (eflag)
82286441Srpaulo		cip_print(length);
83286441Srpaulo
84286441Srpaulo	if (memcmp(rfcllc, p, sizeof(rfcllc)) == 0) {
85286441Srpaulo		/*
86286441Srpaulo		 * LLC header is present.  Try to print it & higher layers.
87286441Srpaulo		 */
88286441Srpaulo		if (llc_print(p, length, caplen, NULL, NULL,
89286441Srpaulo		    &extracted_ethertype) == 0) {
90286441Srpaulo			/* ether_type not known, print raw packet */
91286441Srpaulo			if (!eflag)
92300248Savos				cip_print(length);
93300248Savos			if (extracted_ethertype) {
94286441Srpaulo				printf("(LLC %s) ",
95286441Srpaulo			       etherproto_string(htons(extracted_ethertype)));
96286441Srpaulo			}
97286441Srpaulo			if (!suppress_default_print)
98286441Srpaulo				default_print(p, caplen);
99286441Srpaulo		}
100286441Srpaulo	} else {
101286441Srpaulo		/*
102286441Srpaulo		 * LLC header is absent; treat it as just IP.
103286441Srpaulo		 */
104286441Srpaulo		ip_print(gndo, p, length);
105286441Srpaulo	}
106286441Srpaulo
107286441Srpaulo	return (0);
108286441Srpaulo}
109286441Srpaulo
110286441Srpaulo
111286441Srpaulo/*
112286441Srpaulo * Local Variables:
113286441Srpaulo * c-style: whitesmith
114286441Srpaulo * c-basic-offset: 8
115286441Srpaulo * End:
116286441Srpaulo */
117286441Srpaulo