]>
The Tcpdump Group git mirrors - tcpdump/blob - print-chdlc.c
2 * Copyright (c) 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: Cisco HDLC printer */
28 #include <netdissect-stdinc.h>
30 #include "netdissect.h"
31 #include "addrtoname.h"
32 #include "ethertype.h"
37 static void chdlc_slarp_print(netdissect_options
*, const u_char
*, u_int
);
39 static const struct tok chdlc_cast_values
[] = {
40 { CHDLC_UNICAST
, "unicast" },
41 { CHDLC_BCAST
, "bcast" },
46 /* Standard CHDLC printer */
48 chdlc_if_print(netdissect_options
*ndo
, const struct pcap_pkthdr
*h
, register const u_char
*p
)
50 return chdlc_print(ndo
, p
, h
->len
);
54 chdlc_print(netdissect_options
*ndo
, register const u_char
*p
, u_int length
)
59 if (length
< CHDLC_HDRLEN
)
61 ND_TCHECK2(*p
, CHDLC_HDRLEN
);
62 proto
= EXTRACT_BE_U_2(p
+ 2);
64 ND_PRINT((ndo
, "%s, ethertype %s (0x%04x), length %u: ",
65 tok2str(chdlc_cast_values
, "0x%02x", EXTRACT_U_1(p
)),
66 tok2str(ethertype_values
, "Unknown", proto
),
71 length
-= CHDLC_HDRLEN
;
76 ip_print(ndo
, p
, length
);
79 ip6_print(ndo
, p
, length
);
81 case CHDLC_TYPE_SLARP
:
82 chdlc_slarp_print(ndo
, p
, length
);
86 chdlc_cdp_print(p
, length
);
90 case ETHERTYPE_MPLS_MULTI
:
91 mpls_print(ndo
, p
, length
);
94 /* is the fudge byte set ? lets verify by spotting ISO headers */
98 if (*(p
+1) == NLPID_CLNP
||
99 *(p
+1) == NLPID_ESIS
||
100 *(p
+1) == NLPID_ISIS
)
101 isoclns_print(ndo
, p
+ 1, length
- 1);
103 isoclns_print(ndo
, p
, length
);
107 ND_PRINT((ndo
, "unknown CHDLC protocol (0x%04x)", proto
));
111 return (CHDLC_HDRLEN
);
114 ND_PRINT((ndo
, "[|chdlc]"));
115 return ndo
->ndo_snapend
- bp
;
119 * The fixed-length portion of a SLARP packet.
123 #define SLARP_REQUEST 0
124 #define SLARP_REPLY 1
125 #define SLARP_KEEPALIVE 2
139 #define SLARP_MIN_LEN 14
140 #define SLARP_MAX_LEN 18
143 chdlc_slarp_print(netdissect_options
*ndo
, const u_char
*cp
, u_int length
)
145 const struct cisco_slarp
*slarp
;
146 u_int sec
,min
,hrs
,days
;
148 ND_PRINT((ndo
, "SLARP (length: %u), ",length
));
149 if (length
< SLARP_MIN_LEN
)
152 slarp
= (const struct cisco_slarp
*)cp
;
153 ND_TCHECK2(*slarp
, SLARP_MIN_LEN
);
154 switch (EXTRACT_BE_U_4(&slarp
->code
)) {
156 ND_PRINT((ndo
, "request"));
158 * At least according to William "Chops" Westfield's
161 * http://www.nethelp.no/net/cisco-hdlc.txt
163 * the address and mask aren't used in requests -
168 ND_PRINT((ndo
, "reply %s/%s",
169 ipaddr_string(ndo
, &slarp
->un
.addr
.addr
),
170 ipaddr_string(ndo
, &slarp
->un
.addr
.mask
)));
172 case SLARP_KEEPALIVE
:
173 ND_PRINT((ndo
, "keepalive: mineseen=0x%08x, yourseen=0x%08x, reliability=0x%04x",
174 EXTRACT_BE_U_4(&slarp
->un
.keep
.myseq
),
175 EXTRACT_BE_U_4(&slarp
->un
.keep
.yourseq
),
176 EXTRACT_BE_U_2(&slarp
->un
.keep
.rel
)));
178 if (length
>= SLARP_MAX_LEN
) { /* uptime-stamp is optional */
181 sec
= EXTRACT_BE_U_4(cp
) / 1000;
182 min
= sec
/ 60; sec
-= min
* 60;
183 hrs
= min
/ 60; min
-= hrs
* 60;
184 days
= hrs
/ 24; hrs
-= days
* 24;
185 ND_PRINT((ndo
, ", link uptime=%ud%uh%um%us",days
,hrs
,min
,sec
));
189 ND_PRINT((ndo
, "0x%02x unknown", EXTRACT_BE_U_4(&slarp
->code
)));
190 if (ndo
->ndo_vflag
<= 1)
191 print_unknown_data(ndo
,cp
+4,"\n\t",length
-4);
195 if (SLARP_MAX_LEN
< length
&& ndo
->ndo_vflag
)
196 ND_PRINT((ndo
, ", (trailing junk: %d bytes)", length
- SLARP_MAX_LEN
));
197 if (ndo
->ndo_vflag
> 1)
198 print_unknown_data(ndo
,cp
+4,"\n\t",length
-4);
202 ND_PRINT((ndo
, "[|slarp]"));
208 * c-style: whitesmith