]>
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.
22 #define NETDISSECT_REWORKED
27 #include <tcpdump-stdinc.h>
29 #include "interface.h"
30 #include "extract.h" /* must come after interface.h */
34 #include "slcompress.h"
37 * definitions of the pseudo- link-level header attached to slip
38 * packets grabbed by the packet filter (bpf) traffic monitor.
40 #define SLIP_HDRLEN 16
49 static const char tstr
[] = "[|slip]";
51 static u_int lastlen
[2][256];
52 static u_int lastconn
= 255;
54 static void sliplink_print(netdissect_options
*, const u_char
*, const struct ip
*, u_int
);
55 static void compressed_sl_print(netdissect_options
*, const u_char
*, const struct ip
*, u_int
, int);
58 sl_if_print(netdissect_options
*ndo
,
59 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
|| length
< SLIP_HDRLEN
) {
66 ND_PRINT((ndo
, "%s", tstr
));
70 length
-= SLIP_HDRLEN
;
72 ip
= (struct ip
*)(p
+ SLIP_HDRLEN
);
75 sliplink_print(ndo
, p
, ip
, length
);
79 ip_print(ndo
, (u_char
*)ip
, length
);
82 ip6_print(ndo
, (u_char
*)ip
, length
);
85 ND_PRINT((ndo
, "ip v%d", IP_V(ip
)));
92 sl_bsdos_if_print(netdissect_options
*ndo
,
93 const struct pcap_pkthdr
*h
, const u_char
*p
)
95 register u_int caplen
= h
->caplen
;
96 register u_int length
= h
->len
;
97 register const struct ip
*ip
;
99 if (caplen
< SLIP_HDRLEN
) {
100 ND_PRINT((ndo
, "%s", tstr
));
104 length
-= SLIP_HDRLEN
;
106 ip
= (struct ip
*)(p
+ SLIP_HDRLEN
);
110 sliplink_print(ndo
, p
, ip
, length
);
113 ip_print(ndo
, (u_char
*)ip
, length
);
115 return (SLIP_HDRLEN
);
119 sliplink_print(netdissect_options
*ndo
,
120 register const u_char
*p
, register const struct ip
*ip
,
121 register u_int length
)
127 ND_PRINT((ndo
, dir
== SLIPDIR_IN
? "I " : "O "));
129 if (ndo
->ndo_nflag
) {
130 /* XXX just dump the header */
133 for (i
= SLX_CHDR
; i
< SLX_CHDR
+ CHDR_LEN
- 1; ++i
)
134 ND_PRINT((ndo
, "%02x.", p
[i
]));
135 ND_PRINT((ndo
, "%02x: ", p
[SLX_CHDR
+ CHDR_LEN
- 1]));
138 switch (p
[SLX_CHDR
] & 0xf0) {
141 ND_PRINT((ndo
, "ip %d: ", length
+ SLIP_HDRLEN
));
144 case TYPE_UNCOMPRESSED_TCP
:
146 * The connection id is stored in the IP protocol field.
147 * Get it from the link layer since sl_uncompress_tcp()
148 * has restored the IP header copy to IPPROTO_TCP.
150 lastconn
= ((struct ip
*)&p
[SLX_CHDR
])->ip_p
;
152 hlen
+= TH_OFF((struct tcphdr
*)&((int *)ip
)[hlen
]);
153 lastlen
[dir
][lastconn
] = length
- (hlen
<< 2);
154 ND_PRINT((ndo
, "utcp %d: ", lastconn
));
158 if (p
[SLX_CHDR
] & TYPE_COMPRESSED_TCP
) {
159 compressed_sl_print(ndo
, &p
[SLX_CHDR
], ip
,
161 ND_PRINT((ndo
, ": "));
163 ND_PRINT((ndo
, "slip-%d!: ", p
[SLX_CHDR
]));
167 static const u_char
*
168 print_sl_change(netdissect_options
*ndo
,
169 const char *str
, register const u_char
*cp
)
173 if ((i
= *cp
++) == 0) {
174 i
= EXTRACT_16BITS(cp
);
177 ND_PRINT((ndo
, " %s%d", str
, i
));
181 static const u_char
*
182 print_sl_winchange(netdissect_options
*ndo
,
183 register const u_char
*cp
)
187 if ((i
= *cp
++) == 0) {
188 i
= EXTRACT_16BITS(cp
);
192 ND_PRINT((ndo
, " W+%d", i
));
194 ND_PRINT((ndo
, " W%d", i
));
199 compressed_sl_print(netdissect_options
*ndo
,
200 const u_char
*chdr
, const struct ip
*ip
,
201 u_int length
, int dir
)
203 register const u_char
*cp
= chdr
;
204 register u_int flags
, hlen
;
209 ND_PRINT((ndo
, "ctcp %d", lastconn
));
211 ND_PRINT((ndo
, "ctcp *"));
213 /* skip tcp checksum */
216 switch (flags
& SPECIALS_MASK
) {
218 ND_PRINT((ndo
, " *SA+%d", lastlen
[dir
][lastconn
]));
222 ND_PRINT((ndo
, " *S+%d", lastlen
[dir
][lastconn
]));
227 cp
= print_sl_change(ndo
, "U=", cp
);
229 cp
= print_sl_winchange(ndo
, cp
);
231 cp
= print_sl_change(ndo
, "A+", cp
);
233 cp
= print_sl_change(ndo
, "S+", cp
);
237 cp
= print_sl_change(ndo
, "I+", cp
);
240 * 'hlen' is the length of the uncompressed TCP/IP header (in words).
241 * 'cp - chdr' is the length of the compressed header.
242 * 'length - hlen' is the amount of data in the packet.
245 hlen
+= TH_OFF((struct tcphdr
*)&((int32_t *)ip
)[hlen
]);
246 lastlen
[dir
][lastconn
] = length
- (hlen
<< 2);
247 ND_PRINT((ndo
, " %d (%ld)", lastlen
[dir
][lastconn
], (long)(cp
- chdr
)));