4 * Copyright (c) 1989, 1990, 1991, 1993, 1994, 1995, 1996, 1997
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
24 #include <sys/cdefs.h>
27 static const char rcsid
[] _U_
=
28 "@(#) Header: /tcpdump/master/tcpdump/print-sl.c,v 1.65 2005/04/06 21:32:42 mcr Exp (LBL)";
30 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
38 #include <tcpdump-stdinc.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(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
;
65 if (caplen
< SLIP_HDRLEN
) {
70 length
-= SLIP_HDRLEN
;
72 ip
= (struct ip
*)(p
+ SLIP_HDRLEN
);
75 sliplink_print(p
, ip
, length
);
79 ip_print(gndo
, (u_char
*)ip
, length
);
83 ip6_print((u_char
*)ip
, length
);
87 printf ("ip v%d", IP_V(ip
));
94 sl_bsdos_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
96 register u_int caplen
= h
->caplen
;
97 register u_int length
= h
->len
;
98 register const struct ip
*ip
;
100 if (caplen
< SLIP_HDRLEN
) {
105 length
-= SLIP_HDRLEN
;
107 ip
= (struct ip
*)(p
+ SLIP_HDRLEN
);
111 sliplink_print(p
, ip
, length
);
114 ip_print(gndo
, (u_char
*)ip
, length
);
116 return (SLIP_HDRLEN
);
120 sliplink_print(register const u_char
*p
, register const struct ip
*ip
,
121 register u_int length
)
127 putchar(dir
== SLIPDIR_IN
? 'I' : 'O');
131 /* XXX just dump the header */
134 for (i
= SLX_CHDR
; i
< SLX_CHDR
+ CHDR_LEN
- 1; ++i
)
135 printf("%02x.", p
[i
]);
136 printf("%02x: ", p
[SLX_CHDR
+ CHDR_LEN
- 1]);
139 switch (p
[SLX_CHDR
] & 0xf0) {
142 printf("ip %d: ", length
+ SLIP_HDRLEN
);
145 case TYPE_UNCOMPRESSED_TCP
:
147 * The connection id is stored in the IP protocol field.
148 * Get it from the link layer since sl_uncompress_tcp()
149 * has restored the IP header copy to IPPROTO_TCP.
151 lastconn
= ((struct ip
*)&p
[SLX_CHDR
])->ip_p
;
153 hlen
+= TH_OFF((struct tcphdr
*)&((int *)ip
)[hlen
]);
154 lastlen
[dir
][lastconn
] = length
- (hlen
<< 2);
155 printf("utcp %d: ", lastconn
);
159 if (p
[SLX_CHDR
] & TYPE_COMPRESSED_TCP
) {
160 compressed_sl_print(&p
[SLX_CHDR
], ip
,
164 printf("slip-%d!: ", p
[SLX_CHDR
]);
168 static const u_char
*
169 print_sl_change(const char *str
, register const u_char
*cp
)
173 if ((i
= *cp
++) == 0) {
174 i
= EXTRACT_16BITS(cp
);
177 printf(" %s%d", str
, i
);
181 static const u_char
*
182 print_sl_winchange(register const u_char
*cp
)
186 if ((i
= *cp
++) == 0) {
187 i
= EXTRACT_16BITS(cp
);
198 compressed_sl_print(const u_char
*chdr
, const struct ip
*ip
,
199 u_int length
, int dir
)
201 register const u_char
*cp
= chdr
;
202 register u_int flags
, hlen
;
207 printf("ctcp %d", lastconn
);
211 /* skip tcp checksum */
214 switch (flags
& SPECIALS_MASK
) {
216 printf(" *SA+%d", lastlen
[dir
][lastconn
]);
220 printf(" *S+%d", lastlen
[dir
][lastconn
]);
225 cp
= print_sl_change("U=", cp
);
227 cp
= print_sl_winchange(cp
);
229 cp
= print_sl_change("A+", cp
);
231 cp
= print_sl_change("S+", cp
);
235 cp
= print_sl_change("I+", cp
);
238 * 'hlen' is the length of the uncompressed TCP/IP header (in words).
239 * 'cp - chdr' is the length of the compressed header.
240 * 'length - hlen' is the amount of data in the packet.
243 hlen
+= TH_OFF((struct tcphdr
*)&((int32_t *)ip
)[hlen
]);
244 lastlen
[dir
][lastconn
] = length
- (hlen
<< 2);
245 printf(" %d (%ld)", lastlen
[dir
][lastconn
], (long)(cp
- chdr
));