]>
The Tcpdump Group git mirrors - tcpdump/blob - print-sl.c
2 * Copyright (c) 1989, 1990, 1991, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
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
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.
23 static const char rcsid
[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-sl.c,v 1.53 2000-10-03 02:26:53 itojun Exp $ (LBL)";
31 #ifdef HAVE_NET_SLIP_H
32 #include <sys/param.h>
34 #include <sys/timeb.h>
36 #include <sys/ioctl.h>
38 #include <sys/socket.h>
43 #include <netinet/in.h>
50 #include "interface.h"
51 #include "addrtoname.h"
52 #include "extract.h" /* must come after interface.h */
57 #include <net/slcompress.h>
60 static u_int lastlen
[2][256];
61 static u_int lastconn
= 255;
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);
66 /* XXX BSD/OS 2.1 compatibility */
67 #if !defined(SLIP_HDRLEN) && defined(SLC_BPFHDR)
68 #define SLIP_HDRLEN SLC_BPFHDR
70 #define SLX_CHDR (SLC_BPFHDRLEN - 1)
71 #define CHDR_LEN (SLC_BPFHDR - SLC_BPFHDRLEN)
74 /* XXX needs more hacking to work right */
77 sl_if_print(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*p
)
79 register u_int caplen
= h
->caplen
;
80 register u_int length
= h
->len
;
81 register const struct ip
*ip
;
85 if (caplen
< SLIP_HDRLEN
) {
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.
97 length
-= SLIP_HDRLEN
;
99 ip
= (struct ip
*)(p
+ SLIP_HDRLEN
);
102 sliplink_print(p
, ip
, length
);
106 ip_print((u_char
*)ip
, length
);
110 ip6_print((u_char
*)ip
, length
);
114 printf ("ip v%d", ip
->ip_v
);
118 default_print((u_char
*)ip
, caplen
- SLIP_HDRLEN
);
125 sl_bsdos_if_print(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*p
)
127 register u_int caplen
= h
->caplen
;
128 register u_int length
= h
->len
;
129 register const struct ip
*ip
;
133 if (caplen
< SLIP_HDRLEN
) {
138 * Some printers want to get back at the link level addresses,
139 * and/or check that they're not walking off the end of the packet.
140 * Rather than pass them all the way down, we set these globals.
143 snapend
= p
+ caplen
;
145 length
-= SLIP_HDRLEN
;
147 ip
= (struct ip
*)(p
+ SLIP_HDRLEN
);
151 sliplink_print(p
, ip
, length
);
154 ip_print((u_char
*)ip
, length
);
157 default_print((u_char
*)ip
, caplen
- SLIP_HDRLEN
);
163 sliplink_print(register const u_char
*p
, register const struct ip
*ip
,
164 register u_int length
)
170 putchar(dir
== SLIPDIR_IN
? 'I' : 'O');
174 /* XXX just dump the header */
177 for (i
= SLX_CHDR
; i
< SLX_CHDR
+ CHDR_LEN
- 1; ++i
)
178 printf("%02x.", p
[i
]);
179 printf("%02x: ", p
[SLX_CHDR
+ CHDR_LEN
- 1]);
182 switch (p
[SLX_CHDR
] & 0xf0) {
185 printf("ip %d: ", length
+ SLIP_HDRLEN
);
188 case TYPE_UNCOMPRESSED_TCP
:
190 * The connection id is stored in the IP protocol field.
191 * Get it from the link layer since sl_uncompress_tcp()
192 * has restored the IP header copy to IPPROTO_TCP.
194 lastconn
= ((struct ip
*)&p
[SLX_CHDR
])->ip_p
;
196 hlen
+= TH_OFF((struct tcphdr
*)&((int *)ip
)[hlen
]);
197 lastlen
[dir
][lastconn
] = length
- (hlen
<< 2);
198 printf("utcp %d: ", lastconn
);
202 if (p
[SLX_CHDR
] & TYPE_COMPRESSED_TCP
) {
203 compressed_sl_print(&p
[SLX_CHDR
], ip
,
207 printf("slip-%d!: ", p
[SLX_CHDR
]);
211 static const u_char
*
212 print_sl_change(const char *str
, register const u_char
*cp
)
216 if ((i
= *cp
++) == 0) {
217 i
= EXTRACT_16BITS(cp
);
220 printf(" %s%d", str
, i
);
224 static const u_char
*
225 print_sl_winchange(register const u_char
*cp
)
229 if ((i
= *cp
++) == 0) {
230 i
= EXTRACT_16BITS(cp
);
241 compressed_sl_print(const u_char
*chdr
, const struct ip
*ip
,
242 u_int length
, int dir
)
244 register const u_char
*cp
= chdr
;
245 register u_int flags
, hlen
;
250 printf("ctcp %d", lastconn
);
254 /* skip tcp checksum */
257 switch (flags
& SPECIALS_MASK
) {
259 printf(" *SA+%d", lastlen
[dir
][lastconn
]);
263 printf(" *S+%d", lastlen
[dir
][lastconn
]);
268 cp
= print_sl_change("U=", cp
);
270 cp
= print_sl_winchange(cp
);
272 cp
= print_sl_change("A+", cp
);
274 cp
= print_sl_change("S+", cp
);
278 cp
= print_sl_change("I+", cp
);
281 * 'hlen' is the length of the uncompressed TCP/IP header (in words).
282 * 'cp - chdr' is the length of the compressed header.
283 * 'length - hlen' is the amount of data in the packet.
286 hlen
+= TH_OFF((struct tcphdr
*)&((int32_t *)ip
)[hlen
]);
287 lastlen
[dir
][lastconn
] = length
- (hlen
<< 2);
288 printf(" %d (%d)", lastlen
[dir
][lastconn
], cp
- chdr
);
291 #include <sys/types.h>
292 #include <sys/time.h>
297 #include "interface.h"
300 sl_if_print(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*p
)
303 error("not configured for slip");
308 sl_bsdos_if_print(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*p
)
311 error("not configured for slip");