]> The Tcpdump Group git mirrors - tcpdump/blob - print-sl.c
Eliminate some unused parameters.
[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.57 2001-07-05 18:54:17 guy Exp $ (LBL)";
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <sys/param.h>
32 #include <sys/time.h>
33
34 #include <netinet/in.h>
35
36 #include <ctype.h>
37 #include <netdb.h>
38 #include <pcap.h>
39 #include <stdio.h>
40
41 #include "interface.h"
42 #include "addrtoname.h"
43 #include "extract.h" /* must come after interface.h */
44
45 #include "ip.h"
46 #include "tcp.h"
47 #include "slip.h"
48 #include "slcompress.h"
49
50 static u_int lastlen[2][256];
51 static u_int lastconn = 255;
52
53 static void sliplink_print(const u_char *, const struct ip *, u_int);
54 static void compressed_sl_print(const u_char *, const struct ip *, u_int, int);
55
56 void
57 sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
58 {
59 register u_int caplen = h->caplen;
60 register u_int length = h->len;
61 register const struct ip *ip;
62
63 ++infodelay;
64 ts_print(&h->ts);
65
66 if (caplen < SLIP_HDRLEN) {
67 printf("[|slip]");
68 goto out;
69 }
70 /*
71 * Some printers want to get back at the link level addresses,
72 * and/or check that they're not walking off the end of the packet.
73 * Rather than pass them all the way down, we set these globals.
74 */
75 packetp = p;
76 snapend = p + caplen;
77
78 length -= SLIP_HDRLEN;
79
80 ip = (struct ip *)(p + SLIP_HDRLEN);
81
82 if (eflag)
83 sliplink_print(p, ip, length);
84
85 switch (IP_V(ip)) {
86 case 4:
87 ip_print((u_char *)ip, length);
88 break;
89 #ifdef INET6
90 case 6:
91 ip6_print((u_char *)ip, length);
92 break;
93 #endif
94 default:
95 printf ("ip v%d", IP_V(ip));
96 }
97
98 if (xflag)
99 default_print((u_char *)ip, caplen - SLIP_HDRLEN);
100 out:
101 putchar('\n');
102 --infodelay;
103 if (infoprint)
104 info(0);
105 }
106
107
108 void
109 sl_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
110 {
111 register u_int caplen = h->caplen;
112 register u_int length = h->len;
113 register const struct ip *ip;
114
115 ++infodelay;
116 ts_print(&h->ts);
117
118 if (caplen < SLIP_HDRLEN) {
119 printf("[|slip]");
120 goto out;
121 }
122 /*
123 * Some printers want to get back at the link level addresses,
124 * and/or check that they're not walking off the end of the packet.
125 * Rather than pass them all the way down, we set these globals.
126 */
127 packetp = p;
128 snapend = p + caplen;
129
130 length -= SLIP_HDRLEN;
131
132 ip = (struct ip *)(p + SLIP_HDRLEN);
133
134 #ifdef notdef
135 if (eflag)
136 sliplink_print(p, ip, length);
137 #endif
138
139 ip_print((u_char *)ip, length);
140
141 if (xflag)
142 default_print((u_char *)ip, caplen - SLIP_HDRLEN);
143 out:
144 putchar('\n');
145 --infodelay;
146 if (infoprint)
147 info(0);
148 }
149
150 static void
151 sliplink_print(register const u_char *p, register const struct ip *ip,
152 register u_int length)
153 {
154 int dir;
155 u_int hlen;
156
157 dir = p[SLX_DIR];
158 putchar(dir == SLIPDIR_IN ? 'I' : 'O');
159 putchar(' ');
160
161 if (nflag) {
162 /* XXX just dump the header */
163 register int i;
164
165 for (i = SLX_CHDR; i < SLX_CHDR + CHDR_LEN - 1; ++i)
166 printf("%02x.", p[i]);
167 printf("%02x: ", p[SLX_CHDR + CHDR_LEN - 1]);
168 return;
169 }
170 switch (p[SLX_CHDR] & 0xf0) {
171
172 case TYPE_IP:
173 printf("ip %d: ", length + SLIP_HDRLEN);
174 break;
175
176 case TYPE_UNCOMPRESSED_TCP:
177 /*
178 * The connection id is stored in the IP protocol field.
179 * Get it from the link layer since sl_uncompress_tcp()
180 * has restored the IP header copy to IPPROTO_TCP.
181 */
182 lastconn = ((struct ip *)&p[SLX_CHDR])->ip_p;
183 hlen = IP_HL(ip);
184 hlen += TH_OFF((struct tcphdr *)&((int *)ip)[hlen]);
185 lastlen[dir][lastconn] = length - (hlen << 2);
186 printf("utcp %d: ", lastconn);
187 break;
188
189 default:
190 if (p[SLX_CHDR] & TYPE_COMPRESSED_TCP) {
191 compressed_sl_print(&p[SLX_CHDR], ip,
192 length, dir);
193 printf(": ");
194 } else
195 printf("slip-%d!: ", p[SLX_CHDR]);
196 }
197 }
198
199 static const u_char *
200 print_sl_change(const char *str, register const u_char *cp)
201 {
202 register u_int i;
203
204 if ((i = *cp++) == 0) {
205 i = EXTRACT_16BITS(cp);
206 cp += 2;
207 }
208 printf(" %s%d", str, i);
209 return (cp);
210 }
211
212 static const u_char *
213 print_sl_winchange(register const u_char *cp)
214 {
215 register short i;
216
217 if ((i = *cp++) == 0) {
218 i = EXTRACT_16BITS(cp);
219 cp += 2;
220 }
221 if (i >= 0)
222 printf(" W+%d", i);
223 else
224 printf(" W%d", i);
225 return (cp);
226 }
227
228 static void
229 compressed_sl_print(const u_char *chdr, const struct ip *ip,
230 u_int length, int dir)
231 {
232 register const u_char *cp = chdr;
233 register u_int flags, hlen;
234
235 flags = *cp++;
236 if (flags & NEW_C) {
237 lastconn = *cp++;
238 printf("ctcp %d", lastconn);
239 } else
240 printf("ctcp *");
241
242 /* skip tcp checksum */
243 cp += 2;
244
245 switch (flags & SPECIALS_MASK) {
246 case SPECIAL_I:
247 printf(" *SA+%d", lastlen[dir][lastconn]);
248 break;
249
250 case SPECIAL_D:
251 printf(" *S+%d", lastlen[dir][lastconn]);
252 break;
253
254 default:
255 if (flags & NEW_U)
256 cp = print_sl_change("U=", cp);
257 if (flags & NEW_W)
258 cp = print_sl_winchange(cp);
259 if (flags & NEW_A)
260 cp = print_sl_change("A+", cp);
261 if (flags & NEW_S)
262 cp = print_sl_change("S+", cp);
263 break;
264 }
265 if (flags & NEW_I)
266 cp = print_sl_change("I+", cp);
267
268 /*
269 * 'hlen' is the length of the uncompressed TCP/IP header (in words).
270 * 'cp - chdr' is the length of the compressed header.
271 * 'length - hlen' is the amount of data in the packet.
272 */
273 hlen = IP_HL(ip);
274 hlen += TH_OFF((struct tcphdr *)&((int32_t *)ip)[hlen]);
275 lastlen[dir][lastconn] = length - (hlen << 2);
276 printf(" %d (%ld)", lastlen[dir][lastconn], (long)(cp - chdr));
277 }