]> The Tcpdump Group git mirrors - tcpdump/blob - print-cip.c
Put the infodelay wrapping into the remaining "XXX_if_print()" routines.
[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.14 2001-07-05 18:54:15 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 <sys/param.h>
35 #include <sys/time.h>
36 #include <sys/types.h>
37 #include <sys/socket.h>
38
39
40 #include <netinet/in.h>
41
42 #include <stdio.h>
43 #include <pcap.h>
44
45 #include "interface.h"
46 #include "addrtoname.h"
47 #include "ethertype.h"
48 #include "ether.h"
49
50 #define RFC1483LLC_LEN 8
51
52 static unsigned char rfcllc[] = {
53 0xaa, /* DSAP: non-ISO */
54 0xaa, /* SSAP: non-ISO */
55 0x03, /* Ctrl: Unnumbered Information Command PDU */
56 0x00, /* OUI: EtherType */
57 0x00,
58 0x00 };
59
60 static inline void
61 cip_print(register const u_char *bp, int length)
62 {
63 int i;
64
65 if (memcmp(rfcllc, bp, sizeof(rfcllc))) {
66 if (qflag) {
67 for (i = 0;i < RFC1483LLC_LEN; i++)
68 (void)printf("%2.2x ",bp[i]);
69 } else {
70 for (i = 0;i < RFC1483LLC_LEN - 2; i++)
71 (void)printf("%2.2x ",bp[i]);
72 etherproto_string(((u_short*)bp)[3]);
73 }
74 } else {
75 if (qflag)
76 (void)printf("(null encapsulation)");
77 else {
78 (void)printf("(null encap)");
79 etherproto_string(ETHERTYPE_IP);
80 }
81 }
82 }
83
84 /*
85 * This is the top level routine of the printer. 'p' is the points
86 * to the raw header of the packet, 'tvp' is the timestamp,
87 * 'length' is the length of the packet off the wire, and 'caplen'
88 * is the number of bytes actually captured.
89 */
90 void
91 cip_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
92 {
93 int caplen = h->caplen;
94 int length = h->len;
95 u_short ether_type;
96 u_short extracted_ethertype;
97 u_short *bp;
98
99 ++infodelay;
100 ts_print(&h->ts);
101
102 if (memcmp(rfcllc, p, sizeof(rfcllc))==0 && caplen < RFC1483LLC_LEN) {
103 printf("[|cip]");
104 goto out;
105 }
106
107 if (eflag)
108 cip_print(p, length);
109
110 /*
111 * Some printers want to get back at the ethernet addresses,
112 * and/or check that they're not walking off the end of the packet.
113 * Rather than pass them all the way down, we set these globals.
114 */
115 packetp = p;
116 snapend = p + caplen;
117
118 if (memcmp(rfcllc, p, sizeof(rfcllc))==0) {
119 length -= RFC1483LLC_LEN;
120 caplen -= RFC1483LLC_LEN;
121 bp = (u_short *)p;
122 p += RFC1483LLC_LEN;
123 ether_type = ntohs(bp[3]);
124 } else {
125 ether_type = ETHERTYPE_IP;
126 bp = (u_short *)p;
127 }
128
129 /*
130 * Is it (gag) an 802.3 encapsulation?
131 */
132 extracted_ethertype = 0;
133 if (ether_type < ETHERMTU) {
134 /* Try to print the LLC-layer header & higher layers */
135 if (llc_print(p, length, caplen, NULL, NULL,
136 &extracted_ethertype)==0) {
137 /* ether_type not known, print raw packet */
138 if (!eflag)
139 cip_print((u_char *)bp, length + RFC1483LLC_LEN);
140 if (extracted_ethertype) {
141 printf("(LLC %s) ",
142 etherproto_string(htons(extracted_ethertype)));
143 }
144 if (!xflag && !qflag)
145 default_print(p, caplen);
146 }
147 } else if (ether_encap_print(ether_type, p, length, caplen,
148 &extracted_ethertype) == 0) {
149 /* ether_type not known, print raw packet */
150 if (!eflag)
151 cip_print((u_char *)bp, length + RFC1483LLC_LEN);
152 if (!xflag && !qflag)
153 default_print(p, caplen);
154 }
155 if (xflag)
156 default_print(p, caplen);
157 out:
158 putchar('\n');
159 --infodelay;
160 if (infoprint)
161 info(0);
162 }