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