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