]>
The Tcpdump Group git mirrors - tcpdump/blob - print-sl.c
f714b450540b080e62755d4c174799e2ba54931f
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.51 2000-09-28 06:43:08 guy 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>
44 #include <netinet/in_systm.h>
51 #include "interface.h"
52 #include "addrtoname.h"
53 #include "extract.h" /* must come after interface.h */
58 #include <net/slcompress.h>
61 static u_int lastlen
[2][256];
62 static u_int lastconn
= 255;
64 static void sliplink_print(const u_char
*, const struct ip
*, u_int
);
65 static void compressed_sl_print(const u_char
*, const struct ip
*, u_int
, int);
67 /* XXX BSD/OS 2.1 compatibility */
68 #if !defined(SLIP_HDRLEN) && defined(SLC_BPFHDR)
69 #define SLIP_HDRLEN SLC_BPFHDR
71 #define SLX_CHDR (SLC_BPFHDRLEN - 1)
72 #define CHDR_LEN (SLC_BPFHDR - SLC_BPFHDRLEN)
75 /* XXX needs more hacking to work right */
78 sl_if_print(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*p
)
80 register u_int caplen
= h
->caplen
;
81 register u_int length
= h
->len
;
82 register const struct ip
*ip
;
86 if (caplen
< SLIP_HDRLEN
) {
91 * Some printers want to get back at the link level addresses,
92 * and/or check that they're not walking off the end of the packet.
93 * Rather than pass them all the way down, we set these globals.
98 length
-= SLIP_HDRLEN
;
100 ip
= (struct ip
*)(p
+ SLIP_HDRLEN
);
103 sliplink_print(p
, ip
, length
);
107 ip_print((u_char
*)ip
, length
);
111 ip6_print((u_char
*)ip
, length
);
115 printf ("ip v%d", ip
->ip_v
);
119 default_print((u_char
*)ip
, caplen
- SLIP_HDRLEN
);
126 sl_bsdos_if_print(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*p
)
128 register u_int caplen
= h
->caplen
;
129 register u_int length
= h
->len
;
130 register const struct ip
*ip
;
134 if (caplen
< SLIP_HDRLEN
) {
139 * Some printers want to get back at the link level addresses,
140 * and/or check that they're not walking off the end of the packet.
141 * Rather than pass them all the way down, we set these globals.
144 snapend
= p
+ caplen
;
146 length
-= SLIP_HDRLEN
;
148 ip
= (struct ip
*)(p
+ SLIP_HDRLEN
);
152 sliplink_print(p
, ip
, length
);
155 ip_print((u_char
*)ip
, length
);
158 default_print((u_char
*)ip
, caplen
- SLIP_HDRLEN
);
164 sliplink_print(register const u_char
*p
, register const struct ip
*ip
,
165 register u_int length
)
171 putchar(dir
== SLIPDIR_IN
? 'I' : 'O');
175 /* XXX just dump the header */
178 for (i
= SLX_CHDR
; i
< SLX_CHDR
+ CHDR_LEN
- 1; ++i
)
179 printf("%02x.", p
[i
]);
180 printf("%02x: ", p
[SLX_CHDR
+ CHDR_LEN
- 1]);
183 switch (p
[SLX_CHDR
] & 0xf0) {
186 printf("ip %d: ", length
+ SLIP_HDRLEN
);
189 case TYPE_UNCOMPRESSED_TCP
:
191 * The connection id is stored in the IP protocol field.
192 * Get it from the link layer since sl_uncompress_tcp()
193 * has restored the IP header copy to IPPROTO_TCP.
195 lastconn
= ((struct ip
*)&p
[SLX_CHDR
])->ip_p
;
197 hlen
+= ((struct tcphdr
*)&((int *)ip
)[hlen
])->th_off
;
198 lastlen
[dir
][lastconn
] = length
- (hlen
<< 2);
199 printf("utcp %d: ", lastconn
);
203 if (p
[SLX_CHDR
] & TYPE_COMPRESSED_TCP
) {
204 compressed_sl_print(&p
[SLX_CHDR
], ip
,
208 printf("slip-%d!: ", p
[SLX_CHDR
]);
212 static const u_char
*
213 print_sl_change(const char *str
, register const u_char
*cp
)
217 if ((i
= *cp
++) == 0) {
218 i
= EXTRACT_16BITS(cp
);
221 printf(" %s%d", str
, i
);
225 static const u_char
*
226 print_sl_winchange(register const u_char
*cp
)
230 if ((i
= *cp
++) == 0) {
231 i
= EXTRACT_16BITS(cp
);
242 compressed_sl_print(const u_char
*chdr
, const struct ip
*ip
,
243 u_int length
, int dir
)
245 register const u_char
*cp
= chdr
;
246 register u_int flags
, hlen
;
251 printf("ctcp %d", lastconn
);
255 /* skip tcp checksum */
258 switch (flags
& SPECIALS_MASK
) {
260 printf(" *SA+%d", lastlen
[dir
][lastconn
]);
264 printf(" *S+%d", lastlen
[dir
][lastconn
]);
269 cp
= print_sl_change("U=", cp
);
271 cp
= print_sl_winchange(cp
);
273 cp
= print_sl_change("A+", cp
);
275 cp
= print_sl_change("S+", cp
);
279 cp
= print_sl_change("I+", cp
);
282 * 'hlen' is the length of the uncompressed TCP/IP header (in words).
283 * 'cp - chdr' is the length of the compressed header.
284 * 'length - hlen' is the amount of data in the packet.
287 hlen
+= ((struct tcphdr
*)&((int32_t *)ip
)[hlen
])->th_off
;
288 lastlen
[dir
][lastconn
] = length
- (hlen
<< 2);
289 printf(" %d (%d)", lastlen
[dir
][lastconn
], cp
- chdr
);
292 #include <sys/types.h>
293 #include <sys/time.h>
298 #include "interface.h"
301 sl_if_print(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*p
)
304 error("not configured for slip");
309 sl_bsdos_if_print(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*p
)
312 error("not configured for slip");