]> The Tcpdump Group git mirrors - tcpdump/blob - print-cip.c
e986e52c1cdc1ff2d7329e5ac728df64836f4fa5
[tcpdump] / print-cip.c
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 #ifndef lint
24 static const char rcsid[] =
25 "@(#) $Header: /tcpdump/master/tcpdump/print-cip.c,v 1.19 2002-09-05 21:25:38 guy Exp $ (LBL)";
26 #endif
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include <string.h>
33
34 #include <tcpdump-stdinc.h>
35
36 #include <stdio.h>
37 #include <pcap.h>
38
39 #include "interface.h"
40 #include "addrtoname.h"
41 #include "ethertype.h"
42 #include "ether.h"
43
44 #define RFC1483LLC_LEN 8
45
46 static unsigned char rfcllc[] = {
47 0xaa, /* DSAP: non-ISO */
48 0xaa, /* SSAP: non-ISO */
49 0x03, /* Ctrl: Unnumbered Information Command PDU */
50 0x00, /* OUI: EtherType */
51 0x00,
52 0x00 };
53
54 static inline void
55 cip_print(int length)
56 {
57 /*
58 * There is no MAC-layer header, so just print the length.
59 */
60 printf("%d: ", length);
61 }
62
63 /*
64 * This is the top level routine of the printer. 'p' points
65 * to the LLC/SNAP or raw header of the packet, 'h->ts' is the timestamp,
66 * 'h->length' is the length of the packet off the wire, and 'h->caplen'
67 * is the number of bytes actually captured.
68 */
69 void
70 cip_if_print(u_char *user _U_, const struct pcap_pkthdr *h, const u_char *p)
71 {
72 u_int caplen = h->caplen;
73 u_int length = h->len;
74 u_short extracted_ethertype;
75
76 ++infodelay;
77 ts_print(&h->ts);
78
79 if (memcmp(rfcllc, p, sizeof(rfcllc))==0 && caplen < RFC1483LLC_LEN) {
80 printf("[|cip]");
81 goto out;
82 }
83
84 if (eflag)
85 cip_print(length);
86
87 /*
88 * Some printers want to get back at the ethernet addresses,
89 * and/or check that they're not walking off the end of the packet.
90 * Rather than pass them all the way down, we set these globals.
91 */
92 packetp = p;
93 snapend = p + caplen;
94
95 if (memcmp(rfcllc, p, sizeof(rfcllc)) == 0) {
96 /*
97 * LLC header is present. Try to print it & higher layers.
98 */
99 if (llc_print(p, length, caplen, NULL, NULL,
100 &extracted_ethertype) == 0) {
101 /* ether_type not known, print raw packet */
102 if (!eflag)
103 cip_print(length);
104 if (extracted_ethertype) {
105 printf("(LLC %s) ",
106 etherproto_string(htons(extracted_ethertype)));
107 }
108 if (!xflag && !qflag)
109 default_print(p, caplen);
110 }
111 } else {
112 /*
113 * LLC header is absent; treat it as just IP.
114 */
115 ip_print(p, length);
116 }
117
118 if (xflag)
119 default_print(p, caplen);
120 out:
121 putchar('\n');
122 --infodelay;
123 if (infoprint)
124 info(0);
125 }