]>
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 /* \summary: Compressed Serial Line Internet Protocol printer */
28 #include "netdissect-stdinc.h"
30 #include "netdissect.h"
35 #include "slcompress.h"
38 * definitions of the pseudo- link-level header attached to slip
39 * packets grabbed by the packet filter (bpf) traffic monitor.
41 #define SLIP_HDRLEN 16
51 static u_int lastlen
[2][256];
52 static u_int lastconn
= 255;
54 static int sliplink_print(netdissect_options
*, const u_char
*, const struct ip
*, u_int
);
55 static int 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 u_int caplen
= h
->caplen
;
62 u_int length
= h
->len
;
65 ndo
->ndo_protocol
= "slip";
66 if (caplen
< SLIP_HDRLEN
) {
68 ndo
->ndo_ll_hdr_len
+= caplen
;
71 ndo
->ndo_ll_hdr_len
+= SLIP_HDRLEN
;
73 caplen
-= SLIP_HDRLEN
;
74 length
-= SLIP_HDRLEN
;
76 ip
= (const struct ip
*)(p
+ SLIP_HDRLEN
);
79 if (sliplink_print(ndo
, p
, ip
, length
) == -1) {
86 ip_print(ndo
, (const u_char
*)ip
, length
);
89 ip6_print(ndo
, (const u_char
*)ip
, length
);
92 ND_PRINT("ip v%u", IP_V(ip
));
99 sl_bsdos_if_print(netdissect_options
*ndo
,
100 const struct pcap_pkthdr
*h
, const u_char
*p
)
102 u_int caplen
= h
->caplen
;
103 u_int length
= h
->len
;
106 ndo
->ndo_protocol
= "slip_bsdos";
107 if (caplen
< SLIP_HDRLEN
) {
109 ndo
->ndo_ll_hdr_len
+= caplen
;
112 ndo
->ndo_ll_hdr_len
+= SLIP_HDRLEN
;
114 length
-= SLIP_HDRLEN
;
116 ip
= (const struct ip
*)(p
+ SLIP_HDRLEN
);
120 sliplink_print(ndo
, p
, ip
, length
);
123 ip_print(ndo
, (const u_char
*)ip
, length
);
129 sliplink_print(netdissect_options
*ndo
,
130 const u_char
*p
, const struct ip
*ip
,
136 dir
= GET_U_1(p
+ SLX_DIR
);
148 ND_PRINT("Invalid direction %d ", dir
);
152 switch (GET_U_1(p
+ SLX_CHDR
) & 0xf0) {
155 ND_PRINT("ip %u: ", length
+ SLIP_HDRLEN
);
158 case TYPE_UNCOMPRESSED_TCP
:
160 * The connection id is stored in the IP protocol field.
161 * Get it from the link layer since sl_uncompress_tcp()
162 * has restored the IP header copy to IPPROTO_TCP.
164 lastconn
= GET_U_1(((const struct ip
*)(p
+ SLX_CHDR
))->ip_p
);
165 ND_PRINT("utcp %u: ", lastconn
);
167 /* Direction is bogus, don't use it */
172 ND_TCHECK_SIZE((const struct tcphdr
*)&((const int *)ip
)[hlen
]);
173 hlen
+= TH_OFF((const struct tcphdr
*)&((const int *)ip
)[hlen
]);
174 lastlen
[dir
][lastconn
] = length
- (hlen
<< 2);
179 /* Direction is bogus, don't use it */
182 if (GET_U_1(p
+ SLX_CHDR
) & TYPE_COMPRESSED_TCP
) {
183 if (compressed_sl_print(ndo
, p
+ SLX_CHDR
, ip
,
188 ND_PRINT("slip-%u!: ", GET_U_1(p
+ SLX_CHDR
));
195 static const u_char
*
196 print_sl_change(netdissect_options
*ndo
,
197 const char *str
, const u_char
*cp
)
201 if ((i
= GET_U_1(cp
)) == 0) {
206 ND_PRINT(" %s%u", str
, i
);
210 static const u_char
*
211 print_sl_winchange(netdissect_options
*ndo
,
216 if ((i
= GET_U_1(cp
)) == 0) {
222 ND_PRINT(" W+%d", i
);
229 compressed_sl_print(netdissect_options
*ndo
,
230 const u_char
*chdr
, const struct ip
*ip
,
231 u_int length
, int dir
)
233 const u_char
*cp
= chdr
;
239 lastconn
= GET_U_1(cp
);
241 ND_PRINT("ctcp %u", lastconn
);
245 /* skip tcp checksum */
248 switch (flags
& SPECIALS_MASK
) {
250 ND_PRINT(" *SA+%u", lastlen
[dir
][lastconn
]);
254 ND_PRINT(" *S+%u", lastlen
[dir
][lastconn
]);
259 cp
= print_sl_change(ndo
, "U=", cp
);
261 cp
= print_sl_winchange(ndo
, cp
);
263 cp
= print_sl_change(ndo
, "A+", cp
);
265 cp
= print_sl_change(ndo
, "S+", cp
);
269 cp
= print_sl_change(ndo
, "I+", cp
);
272 * 'hlen' is the length of the uncompressed TCP/IP header (in words).
273 * 'cp - chdr' is the length of the compressed header.
274 * 'length - hlen' is the amount of data in the packet.
278 ND_TCHECK_SIZE((const struct tcphdr
*)&((const int32_t *)ip
)[hlen
]);
279 hlen
+= TH_OFF((const struct tcphdr
*)&((const int32_t *)ip
)[hlen
]);
280 lastlen
[dir
][lastconn
] = length
- (hlen
<< 2);
281 ND_PRINT(" %u (%ld)", lastlen
[dir
][lastconn
], (long)(cp
- chdr
));