]>
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.
23 static const char rcsid
[] _U_
=
24 "@(#) $Header: /tcpdump/master/tcpdump/print-chdlc.c,v 1.32.2.3 2005-04-10 06:42:54 hannes Exp $ (LBL)";
31 #include <tcpdump-stdinc.h>
36 #include "interface.h"
37 #include "addrtoname.h"
38 #include "ethertype.h"
43 static void chdlc_slarp_print(const u_char
*, u_int
);
45 /* Standard CHDLC printer */
47 chdlc_if_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
49 register u_int length
= h
->len
;
50 register u_int caplen
= h
->caplen
;
54 if (caplen
< CHDLC_HDRLEN
) {
59 proto
= EXTRACT_16BITS(&p
[2]);
69 printf("0x%02x ", p
[0]);
72 printf("%d %04x: ", length
, proto
);
75 length
-= CHDLC_HDRLEN
;
76 ip
= (const struct ip
*)(p
+ CHDLC_HDRLEN
);
79 ip_print(gndo
, (const u_char
*)ip
, length
);
83 ip6_print((const u_char
*)ip
, length
);
86 case CHDLC_TYPE_SLARP
:
87 chdlc_slarp_print((const u_char
*)ip
, length
);
91 chdlc_cdp_print((const u_char
*)ip
, length
);
95 case ETHERTYPE_MPLS_MULTI
:
96 mpls_print((const u_char
*)(ip
), length
);
99 /* is the fudge byte set ? lets verify by spotting ISO headers */
100 if (*(p
+CHDLC_HDRLEN
+1) == 0x81 ||
101 *(p
+CHDLC_HDRLEN
+1) == 0x82 ||
102 *(p
+CHDLC_HDRLEN
+1) == 0x83)
103 isoclns_print(p
+CHDLC_HDRLEN
+1, length
-1, length
-1);
105 isoclns_print(p
+CHDLC_HDRLEN
, length
, length
);
108 printf("unknown CHDLC protocol (0x%04x)", proto
);
112 return (CHDLC_HDRLEN
);
117 #define SLARP_REQUEST 0
118 #define SLARP_REPLY 1
119 #define SLARP_KEEPALIVE 2
137 chdlc_slarp_print(const u_char
*cp
, u_int length
)
139 const struct cisco_slarp
*slarp
;
140 u_int sec
,min
,hrs
,days
;
142 printf("SLARP (length: %u), ",length
);
143 if (length
< SLARP_LEN
)
146 slarp
= (const struct cisco_slarp
*)cp
;
148 switch (EXTRACT_32BITS(&slarp
->code
)) {
151 /* ok we do not know it - but lets at least dump it */
152 print_unknown_data(cp
+4,"\n\t",length
-4);
155 printf("reply %s/%s",
156 ipaddr_string(&slarp
->un
.addr
.addr
),
157 ipaddr_string(&slarp
->un
.addr
.mask
));
159 case SLARP_KEEPALIVE
:
160 printf("keepalive: mineseen=0x%08x, yourseen=0x%08x, reliability=0x%04x",
161 EXTRACT_32BITS(&slarp
->un
.keep
.myseq
),
162 EXTRACT_32BITS(&slarp
->un
.keep
.yourseq
),
163 EXTRACT_16BITS(&slarp
->un
.keep
.rel
));
165 if (length
>= SLARP_LEN
) { /* uptime-stamp is optional */
166 if (!TTEST2(slarp
->un
.keep
.time
, 4))
168 sec
= EXTRACT_32BITS(&slarp
->un
.keep
.time
) / 1000;
169 min
= sec
/ 60; sec
-= min
* 60;
170 hrs
= min
/ 60; min
-= hrs
* 60;
171 days
= hrs
/ 24; hrs
-= days
* 24;
172 printf(", link uptime=%ud%uh%um%us",days
,hrs
,min
,sec
);
176 printf("0x%02x unknown", EXTRACT_32BITS(&slarp
->code
));
178 print_unknown_data(cp
+4,"\n\t",length
-4);
182 if (SLARP_LEN
< length
&& vflag
)
183 printf(", (trailing junk: %d bytes)", length
- SLARP_LEN
);
185 print_unknown_data(cp
+4,"\n\t",length
-4);
195 * c-style: whitesmith