4 * Copyright (c) 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-chdlc.c,v 1.32.2.11 2005/11/29 08:57:10 hannes 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 "ethertype.h"
50 static void chdlc_slarp_print(const u_char
*, u_int
);
52 const struct tok chdlc_cast_values
[] = {
53 { CHDLC_UNICAST
, "unicast" },
54 { CHDLC_BCAST
, "bcast" },
59 /* Standard CHDLC printer */
61 chdlc_if_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
63 register u_int length
= h
->len
;
64 register u_int caplen
= h
->caplen
;
66 if (caplen
< CHDLC_HDRLEN
) {
70 return (chdlc_print(p
,length
));
74 chdlc_print(register const u_char
*p
, u_int length
) {
77 proto
= EXTRACT_16BITS(&p
[2]);
79 printf("%s, ethertype %s (0x%04x), length %u: ",
80 tok2str(chdlc_cast_values
, "0x%02x", p
[0]),
81 tok2str(ethertype_values
, "Unknown", proto
),
86 length
-= CHDLC_HDRLEN
;
91 ip_print(gndo
, p
, length
);
98 case CHDLC_TYPE_SLARP
:
99 chdlc_slarp_print(p
, length
);
103 chdlc_cdp_print(p
, length
);
107 case ETHERTYPE_MPLS_MULTI
:
108 mpls_print(p
, length
);
111 /* is the fudge byte set ? lets verify by spotting ISO headers */
112 if (*(p
+1) == 0x81 ||
115 isoclns_print(p
+1, length
-1, length
-1);
117 isoclns_print(p
, length
, length
);
121 printf("unknown CHDLC protocol (0x%04x)", proto
);
125 return (CHDLC_HDRLEN
);
129 * The fixed-length portion of a SLARP packet.
133 #define SLARP_REQUEST 0
134 #define SLARP_REPLY 1
135 #define SLARP_KEEPALIVE 2
149 #define SLARP_MIN_LEN 14
150 #define SLARP_MAX_LEN 18
153 chdlc_slarp_print(const u_char
*cp
, u_int length
)
155 const struct cisco_slarp
*slarp
;
156 u_int sec
,min
,hrs
,days
;
158 printf("SLARP (length: %u), ",length
);
159 if (length
< SLARP_MIN_LEN
)
162 slarp
= (const struct cisco_slarp
*)cp
;
163 TCHECK2(*slarp
, SLARP_MIN_LEN
);
164 switch (EXTRACT_32BITS(&slarp
->code
)) {
168 * At least according to William "Chops" Westfield's
171 * http://www.nethelp.no/net/cisco-hdlc.txt
173 * the address and mask aren't used in requests -
178 printf("reply %s/%s",
179 ipaddr_string(&slarp
->un
.addr
.addr
),
180 ipaddr_string(&slarp
->un
.addr
.mask
));
182 case SLARP_KEEPALIVE
:
183 printf("keepalive: mineseen=0x%08x, yourseen=0x%08x, reliability=0x%04x",
184 EXTRACT_32BITS(&slarp
->un
.keep
.myseq
),
185 EXTRACT_32BITS(&slarp
->un
.keep
.yourseq
),
186 EXTRACT_16BITS(&slarp
->un
.keep
.rel
));
188 if (length
>= SLARP_MAX_LEN
) { /* uptime-stamp is optional */
192 sec
= EXTRACT_32BITS(cp
) / 1000;
193 min
= sec
/ 60; sec
-= min
* 60;
194 hrs
= min
/ 60; min
-= hrs
* 60;
195 days
= hrs
/ 24; hrs
-= days
* 24;
196 printf(", link uptime=%ud%uh%um%us",days
,hrs
,min
,sec
);
200 printf("0x%02x unknown", EXTRACT_32BITS(&slarp
->code
));
202 print_unknown_data(cp
+4,"\n\t",length
-4);
206 if (SLARP_MAX_LEN
< length
&& vflag
)
207 printf(", (trailing junk: %d bytes)", length
- SLARP_MAX_LEN
);
209 print_unknown_data(cp
+4,"\n\t",length
-4);
219 * c-style: whitesmith