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.57 2001/07/05 18:54:17 guy Exp $ (LBL)";
33 #include <sys/param.h>
36 #include <netinet/in.h>
43 #include "interface.h"
44 #include "addrtoname.h"
45 #include "extract.h" /* must come after interface.h */
50 #include "slcompress.h"
52 static u_int lastlen[2][256];
53 static u_int lastconn = 255;
55 static void sliplink_print(const u_char *, const struct ip *, u_int);
56 static void compressed_sl_print(const u_char *, const struct ip *, u_int, int);
59 sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
61 register u_int caplen = h->caplen;
62 register u_int length = h->len;
63 register const struct ip *ip;
68 if (caplen < SLIP_HDRLEN) {
73 * Some printers want to get back at the link level addresses,
74 * and/or check that they're not walking off the end of the packet.
75 * Rather than pass them all the way down, we set these globals.
80 length -= SLIP_HDRLEN;
82 ip = (struct ip *)(p + SLIP_HDRLEN);
85 sliplink_print(p, ip, length);
89 ip_print((u_char *)ip, length);
93 ip6_print((u_char *)ip, length);
97 printf ("ip v%d", IP_V(ip));
101 default_print((u_char *)ip, caplen - SLIP_HDRLEN);
111 sl_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
113 register u_int caplen = h->caplen;
114 register u_int length = h->len;
115 register const struct ip *ip;
120 if (caplen < SLIP_HDRLEN) {
125 * Some printers want to get back at the link level addresses,
126 * and/or check that they're not walking off the end of the packet.
127 * Rather than pass them all the way down, we set these globals.
130 snapend = p + caplen;
132 length -= SLIP_HDRLEN;
134 ip = (struct ip *)(p + SLIP_HDRLEN);
138 sliplink_print(p, ip, length);
141 ip_print((u_char *)ip, length);
144 default_print((u_char *)ip, caplen - SLIP_HDRLEN);
153 sliplink_print(register const u_char *p, register const struct ip *ip,
154 register u_int length)
160 putchar(dir == SLIPDIR_IN ? 'I' : 'O');
164 /* XXX just dump the header */
167 for (i = SLX_CHDR; i < SLX_CHDR + CHDR_LEN - 1; ++i)
168 printf("%02x.", p[i]);
169 printf("%02x: ", p[SLX_CHDR + CHDR_LEN - 1]);
172 switch (p[SLX_CHDR] & 0xf0) {
175 printf("ip %d: ", length + SLIP_HDRLEN);
178 case TYPE_UNCOMPRESSED_TCP:
180 * The connection id is stored in the IP protocol field.
181 * Get it from the link layer since sl_uncompress_tcp()
182 * has restored the IP header copy to IPPROTO_TCP.
184 lastconn = ((struct ip *)&p[SLX_CHDR])->ip_p;
186 hlen += TH_OFF((struct tcphdr *)&((int *)ip)[hlen]);
187 lastlen[dir][lastconn] = length - (hlen << 2);
188 printf("utcp %d: ", lastconn);
192 if (p[SLX_CHDR] & TYPE_COMPRESSED_TCP) {
193 compressed_sl_print(&p[SLX_CHDR], ip,
197 printf("slip-%d!: ", p[SLX_CHDR]);
201 static const u_char *
202 print_sl_change(const char *str, register const u_char *cp)
206 if ((i = *cp++) == 0) {
207 i = EXTRACT_16BITS(cp);
210 printf(" %s%d", str, i);
214 static const u_char *
215 print_sl_winchange(register const u_char *cp)
219 if ((i = *cp++) == 0) {
220 i = EXTRACT_16BITS(cp);
231 compressed_sl_print(const u_char *chdr, const struct ip *ip,
232 u_int length, int dir)
234 register const u_char *cp = chdr;
235 register u_int flags, hlen;
240 printf("ctcp %d", lastconn);
244 /* skip tcp checksum */
247 switch (flags & SPECIALS_MASK) {
249 printf(" *SA+%d", lastlen[dir][lastconn]);
253 printf(" *S+%d", lastlen[dir][lastconn]);
258 cp = print_sl_change("U=", cp);
260 cp = print_sl_winchange(cp);
262 cp = print_sl_change("A+", cp);
264 cp = print_sl_change("S+", cp);
268 cp = print_sl_change("I+", cp);
271 * 'hlen' is the length of the uncompressed TCP/IP header (in words).
272 * 'cp - chdr' is the length of the compressed header.
273 * 'length - hlen' is the amount of data in the packet.
276 hlen += TH_OFF((struct tcphdr *)&((int32_t *)ip)[hlen]);
277 lastlen[dir][lastconn] = length - (hlen << 2);
278 printf(" %d (%ld)", lastlen[dir][lastconn], (long)(cp - chdr));