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.
25 static const char rcsid[] =
26 "@(#) $Header: /tcpdump/master/tcpdump/print-sl.c,v 1.46 1999/11/21 12:38:24 itojun Exp $ (LBL)";
33 #ifdef HAVE_NET_SLIP_H
34 #include <sys/param.h>
36 #include <sys/timeb.h>
38 #include <sys/ioctl.h>
40 #include <sys/socket.h>
47 #include <netinet/in.h>
48 #include <netinet/in_systm.h>
49 #include <netinet/ip.h>
50 #include <net/ethernet.h>
51 #include <netinet/ip_var.h>
52 #include <netinet/udp.h>
53 #include <netinet/tcp.h>
55 #include <net/slcompress.h>
63 #include "interface.h"
64 #include "addrtoname.h"
65 #include "extract.h" /* must come after interface.h */
67 static u_int lastlen[2][256];
68 static u_int lastconn = 255;
70 static void sliplink_print(const u_char *, const struct ip *, u_int);
71 static void compressed_sl_print(const u_char *, const struct ip *, u_int, int);
73 /* XXX BSD/OS 2.1 compatibility */
74 #if !defined(SLIP_HDRLEN) && defined(SLC_BPFHDR)
75 #define SLIP_HDRLEN SLC_BPFHDR
77 #define SLX_CHDR (SLC_BPFHDRLEN - 1)
78 #define CHDR_LEN (SLC_BPFHDR - SLC_BPFHDRLEN)
81 /* XXX needs more hacking to work right */
84 sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
86 register u_int caplen = h->caplen;
87 register u_int length = h->len;
88 register const struct ip *ip;
92 if (caplen < SLIP_HDRLEN) {
97 * Some printers want to get back at the link level addresses,
98 * and/or check that they're not walking off the end of the packet.
99 * Rather than pass them all the way down, we set these globals.
102 snapend = p + caplen;
104 length -= SLIP_HDRLEN;
106 ip = (struct ip *)(p + SLIP_HDRLEN);
109 sliplink_print(p, ip, length);
113 ip_print((u_char *)ip, length);
117 ip6_print((u_char *)ip, length);
121 printf ("ip v%d", ip->ip_v);
125 default_print((u_char *)ip, caplen - SLIP_HDRLEN);
132 sl_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
134 register u_int caplen = h->caplen;
135 register u_int length = h->len;
136 register const struct ip *ip;
140 if (caplen < SLIP_HDRLEN) {
145 * Some printers want to get back at the link level addresses,
146 * and/or check that they're not walking off the end of the packet.
147 * Rather than pass them all the way down, we set these globals.
150 snapend = p + caplen;
152 length -= SLIP_HDRLEN;
154 ip = (struct ip *)(p + SLIP_HDRLEN);
158 sliplink_print(p, ip, length);
161 ip_print((u_char *)ip, length);
164 default_print((u_char *)ip, caplen - SLIP_HDRLEN);
170 sliplink_print(register const u_char *p, register const struct ip *ip,
171 register u_int length)
177 putchar(dir == SLIPDIR_IN ? 'I' : 'O');
181 /* XXX just dump the header */
184 for (i = SLX_CHDR; i < SLX_CHDR + CHDR_LEN - 1; ++i)
185 printf("%02x.", p[i]);
186 printf("%02x: ", p[SLX_CHDR + CHDR_LEN - 1]);
189 switch (p[SLX_CHDR] & 0xf0) {
192 printf("ip %d: ", length + SLIP_HDRLEN);
195 case TYPE_UNCOMPRESSED_TCP:
197 * The connection id is stored in the IP protocol field.
198 * Get it from the link layer since sl_uncompress_tcp()
199 * has restored the IP header copy to IPPROTO_TCP.
201 lastconn = ((struct ip *)&p[SLX_CHDR])->ip_p;
203 hlen += ((struct tcphdr *)&((int *)ip)[hlen])->th_off;
204 lastlen[dir][lastconn] = length - (hlen << 2);
205 printf("utcp %d: ", lastconn);
209 if (p[SLX_CHDR] & TYPE_COMPRESSED_TCP) {
210 compressed_sl_print(&p[SLX_CHDR], ip,
214 printf("slip-%d!: ", p[SLX_CHDR]);
218 static const u_char *
219 print_sl_change(const char *str, register const u_char *cp)
223 if ((i = *cp++) == 0) {
224 i = EXTRACT_16BITS(cp);
227 printf(" %s%d", str, i);
231 static const u_char *
232 print_sl_winchange(register const u_char *cp)
236 if ((i = *cp++) == 0) {
237 i = EXTRACT_16BITS(cp);
248 compressed_sl_print(const u_char *chdr, const struct ip *ip,
249 u_int length, int dir)
251 register const u_char *cp = chdr;
252 register u_int flags, hlen;
257 printf("ctcp %d", lastconn);
261 /* skip tcp checksum */
264 switch (flags & SPECIALS_MASK) {
266 printf(" *SA+%d", lastlen[dir][lastconn]);
270 printf(" *S+%d", lastlen[dir][lastconn]);
275 cp = print_sl_change("U=", cp);
277 cp = print_sl_winchange(cp);
279 cp = print_sl_change("A+", cp);
281 cp = print_sl_change("S+", cp);
285 cp = print_sl_change("I+", cp);
288 * 'hlen' is the length of the uncompressed TCP/IP header (in words).
289 * 'cp - chdr' is the length of the compressed header.
290 * 'length - hlen' is the amount of data in the packet.
293 hlen += ((struct tcphdr *)&((int32_t *)ip)[hlen])->th_off;
294 lastlen[dir][lastconn] = length - (hlen << 2);
295 printf(" %d (%d)", lastlen[dir][lastconn], cp - chdr);
298 #include <sys/types.h>
299 #include <sys/time.h>
304 #include "interface.h"
307 sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
310 error("not configured for slip");
315 sl_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
318 error("not configured for slip");