]>
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
50 static const char tstr
[] = "[|slip]";
52 static u_int lastlen
[2][256];
53 static u_int lastconn
= 255;
55 static void sliplink_print(netdissect_options
*, const u_char
*, const struct ip
*, u_int
);
56 static void compressed_sl_print(netdissect_options
*, const u_char
*, const struct ip
*, u_int
, int);
59 sl_if_print(netdissect_options
*ndo
,
60 const struct pcap_pkthdr
*h
, const u_char
*p
)
62 register u_int caplen
= h
->caplen
;
63 register u_int length
= h
->len
;
64 register const struct ip
*ip
;
66 if (caplen
< SLIP_HDRLEN
|| length
< SLIP_HDRLEN
) {
67 ND_PRINT((ndo
, "%s", tstr
));
71 caplen
-= SLIP_HDRLEN
;
72 length
-= SLIP_HDRLEN
;
74 ip
= (const struct ip
*)(p
+ SLIP_HDRLEN
);
77 sliplink_print(ndo
, p
, ip
, length
);
79 if (caplen
< 1 || length
< 1) {
80 ND_PRINT((ndo
, "%s", tstr
));
81 return (caplen
+ SLIP_HDRLEN
);
86 ip_print(ndo
, (const u_char
*)ip
, length
);
89 ip6_print(ndo
, (const u_char
*)ip
, length
);
92 ND_PRINT((ndo
, "ip v%d", IP_V(ip
)));
99 sl_bsdos_if_print(netdissect_options
*ndo
,
100 const struct pcap_pkthdr
*h
, const u_char
*p
)
102 register u_int caplen
= h
->caplen
;
103 register u_int length
= h
->len
;
104 register const struct ip
*ip
;
106 if (caplen
< SLIP_HDRLEN
) {
107 ND_PRINT((ndo
, "%s", tstr
));
111 length
-= SLIP_HDRLEN
;
113 ip
= (const struct ip
*)(p
+ SLIP_HDRLEN
);
117 sliplink_print(ndo
, p
, ip
, length
);
120 ip_print(ndo
, (const u_char
*)ip
, length
);
122 return (SLIP_HDRLEN
);
126 sliplink_print(netdissect_options
*ndo
,
127 register const u_char
*p
, register const struct ip
*ip
,
128 register u_int length
)
137 ND_PRINT((ndo
, "I "));
141 ND_PRINT((ndo
, "O "));
145 ND_PRINT((ndo
, "Invalid direction %d ", dir
));
149 if (ndo
->ndo_nflag
) {
150 /* XXX just dump the header */
153 for (i
= SLX_CHDR
; i
< SLX_CHDR
+ CHDR_LEN
- 1; ++i
)
154 ND_PRINT((ndo
, "%02x.", EXTRACT_U_1(p
+ i
)));
155 ND_PRINT((ndo
, "%02x: ", EXTRACT_U_1(p
+ SLX_CHDR
+ CHDR_LEN
- 1)));
158 switch (p
[SLX_CHDR
] & 0xf0) {
161 ND_PRINT((ndo
, "ip %d: ", length
+ SLIP_HDRLEN
));
164 case TYPE_UNCOMPRESSED_TCP
:
166 * The connection id is stored in the IP protocol field.
167 * Get it from the link layer since sl_uncompress_tcp()
168 * has restored the IP header copy to IPPROTO_TCP.
170 lastconn
= ((const struct ip
*)&p
[SLX_CHDR
])->ip_p
;
171 ND_PRINT((ndo
, "utcp %d: ", lastconn
));
173 /* Direction is bogus, don't use it */
177 hlen
+= TH_OFF((const struct tcphdr
*)&((const int *)ip
)[hlen
]);
178 lastlen
[dir
][lastconn
] = length
- (hlen
<< 2);
183 /* Direction is bogus, don't use it */
186 if (p
[SLX_CHDR
] & TYPE_COMPRESSED_TCP
) {
187 compressed_sl_print(ndo
, &p
[SLX_CHDR
], ip
,
189 ND_PRINT((ndo
, ": "));
191 ND_PRINT((ndo
, "slip-%d!: ", EXTRACT_U_1(p
+ SLX_CHDR
)));
195 static const u_char
*
196 print_sl_change(netdissect_options
*ndo
,
197 const char *str
, register const u_char
*cp
)
201 if ((i
= *cp
++) == 0) {
202 i
= EXTRACT_BE_U_2(cp
);
205 ND_PRINT((ndo
, " %s%d", str
, i
));
209 static const u_char
*
210 print_sl_winchange(netdissect_options
*ndo
,
211 register const u_char
*cp
)
215 if ((i
= *cp
++) == 0) {
216 i
= EXTRACT_BE_U_2(cp
);
220 ND_PRINT((ndo
, " W+%d", i
));
222 ND_PRINT((ndo
, " W%d", i
));
227 compressed_sl_print(netdissect_options
*ndo
,
228 const u_char
*chdr
, const struct ip
*ip
,
229 u_int length
, int dir
)
231 register const u_char
*cp
= chdr
;
232 register u_int flags
, hlen
;
234 flags
= EXTRACT_U_1(cp
);
237 lastconn
= EXTRACT_U_1(cp
);
239 ND_PRINT((ndo
, "ctcp %d", lastconn
));
241 ND_PRINT((ndo
, "ctcp *"));
243 /* skip tcp checksum */
246 switch (flags
& SPECIALS_MASK
) {
248 ND_PRINT((ndo
, " *SA+%d", lastlen
[dir
][lastconn
]));
252 ND_PRINT((ndo
, " *S+%d", lastlen
[dir
][lastconn
]));
257 cp
= print_sl_change(ndo
, "U=", cp
);
259 cp
= print_sl_winchange(ndo
, cp
);
261 cp
= print_sl_change(ndo
, "A+", cp
);
263 cp
= print_sl_change(ndo
, "S+", cp
);
267 cp
= print_sl_change(ndo
, "I+", cp
);
270 * 'hlen' is the length of the uncompressed TCP/IP header (in words).
271 * 'cp - chdr' is the length of the compressed header.
272 * 'length - hlen' is the amount of data in the packet.
275 hlen
+= TH_OFF((const struct tcphdr
*)&((const int32_t *)ip
)[hlen
]);
276 lastlen
[dir
][lastconn
] = length
- (hlen
<< 2);
277 ND_PRINT((ndo
, " %d (%ld)", lastlen
[dir
][lastconn
], (long)(cp
- chdr
)));