]> The Tcpdump Group git mirrors - tcpdump/blob - print-sl.c
add code for printing MakeDir and StoreStatus. Also change date
[tcpdump] / print-sl.c
1 /*
2 * Copyright (c) 1989, 1990, 1991, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 */
21
22 #ifndef lint
23 static const char rcsid[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-sl.c,v 1.43 1999-10-17 21:37:15 mcr Exp $ (LBL)";
25 #endif
26
27 #ifdef HAVE_NET_SLIP_H
28 #include <sys/param.h>
29 #include <sys/time.h>
30 #include <sys/timeb.h>
31 #include <sys/file.h>
32 #include <sys/ioctl.h>
33 #include <sys/mbuf.h>
34 #include <sys/socket.h>
35
36 #if __STDC__
37 struct rtentry;
38 #endif
39 #include <net/if.h>
40
41 #include <netinet/in.h>
42 #include <netinet/in_systm.h>
43 #include <netinet/ip.h>
44 #include <netinet/if_ether.h>
45 #include <netinet/udp.h>
46 #include <netinet/tcp.h>
47
48 #include <net/slcompress.h>
49 #include <net/slip.h>
50
51 #include <ctype.h>
52 #include <netdb.h>
53 #include <pcap.h>
54 #include <stdio.h>
55
56 #include "interface.h"
57 #include "addrtoname.h"
58 #include "extract.h" /* must come after interface.h */
59
60 static u_int lastlen[2][256];
61 static u_int lastconn = 255;
62
63 static void sliplink_print(const u_char *, const struct ip *, u_int);
64 static void compressed_sl_print(const u_char *, const struct ip *, u_int, int);
65
66 /* XXX BSD/OS 2.1 compatibility */
67 #if !defined(SLIP_HDRLEN) && defined(SLC_BPFHDR)
68 #define SLIP_HDRLEN SLC_BPFHDR
69 #define SLX_DIR 0
70 #define SLX_CHDR (SLC_BPFHDRLEN - 1)
71 #define CHDR_LEN (SLC_BPFHDR - SLC_BPFHDRLEN)
72 #endif
73
74 /* XXX needs more hacking to work right */
75
76 void
77 sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
78 {
79 register u_int caplen = h->caplen;
80 register u_int length = h->len;
81 register const struct ip *ip;
82
83 ts_print(&h->ts);
84
85 if (caplen < SLIP_HDRLEN) {
86 printf("[|slip]");
87 goto out;
88 }
89 /*
90 * Some printers want to get back at the link level addresses,
91 * and/or check that they're not walking off the end of the packet.
92 * Rather than pass them all the way down, we set these globals.
93 */
94 packetp = p;
95 snapend = p + caplen;
96
97 length -= SLIP_HDRLEN;
98
99 ip = (struct ip *)(p + SLIP_HDRLEN);
100
101 if (eflag)
102 sliplink_print(p, ip, length);
103
104 ip_print((u_char *)ip, length);
105
106 if (xflag)
107 default_print((u_char *)ip, caplen - SLIP_HDRLEN);
108 out:
109 putchar('\n');
110 }
111
112
113 void
114 sl_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
115 {
116 register u_int caplen = h->caplen;
117 register u_int length = h->len;
118 register const struct ip *ip;
119
120 ts_print(&h->ts);
121
122 if (caplen < SLIP_HDRLEN) {
123 printf("[|slip]");
124 goto out;
125 }
126 /*
127 * Some printers want to get back at the link level addresses,
128 * and/or check that they're not walking off the end of the packet.
129 * Rather than pass them all the way down, we set these globals.
130 */
131 packetp = p;
132 snapend = p + caplen;
133
134 length -= SLIP_HDRLEN;
135
136 ip = (struct ip *)(p + SLIP_HDRLEN);
137
138 #ifdef notdef
139 if (eflag)
140 sliplink_print(p, ip, length);
141 #endif
142
143 ip_print((u_char *)ip, length);
144
145 if (xflag)
146 default_print((u_char *)ip, caplen - SLIP_HDRLEN);
147 out:
148 putchar('\n');
149 }
150
151 static void
152 sliplink_print(register const u_char *p, register const struct ip *ip,
153 register u_int length)
154 {
155 int dir;
156 u_int hlen;
157
158 dir = p[SLX_DIR];
159 putchar(dir == SLIPDIR_IN ? 'I' : 'O');
160 putchar(' ');
161
162 if (nflag) {
163 /* XXX just dump the header */
164 register int i;
165
166 for (i = SLX_CHDR; i < SLX_CHDR + CHDR_LEN - 1; ++i)
167 printf("%02x.", p[i]);
168 printf("%02x: ", p[SLX_CHDR + CHDR_LEN - 1]);
169 return;
170 }
171 switch (p[SLX_CHDR] & 0xf0) {
172
173 case TYPE_IP:
174 printf("ip %d: ", length + SLIP_HDRLEN);
175 break;
176
177 case TYPE_UNCOMPRESSED_TCP:
178 /*
179 * The connection id is stored in the IP protocol field.
180 * Get it from the link layer since sl_uncompress_tcp()
181 * has restored the IP header copy to IPPROTO_TCP.
182 */
183 lastconn = ((struct ip *)&p[SLX_CHDR])->ip_p;
184 hlen = ip->ip_hl;
185 hlen += ((struct tcphdr *)&((int *)ip)[hlen])->th_off;
186 lastlen[dir][lastconn] = length - (hlen << 2);
187 printf("utcp %d: ", lastconn);
188 break;
189
190 default:
191 if (p[SLX_CHDR] & TYPE_COMPRESSED_TCP) {
192 compressed_sl_print(&p[SLX_CHDR], ip,
193 length, dir);
194 printf(": ");
195 } else
196 printf("slip-%d!: ", p[SLX_CHDR]);
197 }
198 }
199
200 static const u_char *
201 print_sl_change(const char *str, register const u_char *cp)
202 {
203 register u_int i;
204
205 if ((i = *cp++) == 0) {
206 i = EXTRACT_16BITS(cp);
207 cp += 2;
208 }
209 printf(" %s%d", str, i);
210 return (cp);
211 }
212
213 static const u_char *
214 print_sl_winchange(register const u_char *cp)
215 {
216 register short i;
217
218 if ((i = *cp++) == 0) {
219 i = EXTRACT_16BITS(cp);
220 cp += 2;
221 }
222 if (i >= 0)
223 printf(" W+%d", i);
224 else
225 printf(" W%d", i);
226 return (cp);
227 }
228
229 static void
230 compressed_sl_print(const u_char *chdr, const struct ip *ip,
231 u_int length, int dir)
232 {
233 register const u_char *cp = chdr;
234 register u_int flags, hlen;
235
236 flags = *cp++;
237 if (flags & NEW_C) {
238 lastconn = *cp++;
239 printf("ctcp %d", lastconn);
240 } else
241 printf("ctcp *");
242
243 /* skip tcp checksum */
244 cp += 2;
245
246 switch (flags & SPECIALS_MASK) {
247 case SPECIAL_I:
248 printf(" *SA+%d", lastlen[dir][lastconn]);
249 break;
250
251 case SPECIAL_D:
252 printf(" *S+%d", lastlen[dir][lastconn]);
253 break;
254
255 default:
256 if (flags & NEW_U)
257 cp = print_sl_change("U=", cp);
258 if (flags & NEW_W)
259 cp = print_sl_winchange(cp);
260 if (flags & NEW_A)
261 cp = print_sl_change("A+", cp);
262 if (flags & NEW_S)
263 cp = print_sl_change("S+", cp);
264 break;
265 }
266 if (flags & NEW_I)
267 cp = print_sl_change("I+", cp);
268
269 /*
270 * 'hlen' is the length of the uncompressed TCP/IP header (in words).
271 * 'cp - chdr' is the length of the compressed header.
272 * 'length - hlen' is the amount of data in the packet.
273 */
274 hlen = ip->ip_hl;
275 hlen += ((struct tcphdr *)&((int32_t *)ip)[hlen])->th_off;
276 lastlen[dir][lastconn] = length - (hlen << 2);
277 printf(" %d (%d)", lastlen[dir][lastconn], cp - chdr);
278 }
279 #else
280 #include <sys/types.h>
281 #include <sys/time.h>
282
283 #include <pcap.h>
284 #include <stdio.h>
285
286 #include "interface.h"
287
288 void
289 sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
290 {
291
292 error("not configured for slip");
293 /* NOTREACHED */
294 }
295
296 void
297 sl_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
298 {
299
300 error("not configured for slip");
301 /* NOTREACHED */
302 }
303 #endif