]>
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
[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-chdlc.c,v 1.22 2002-11-09 17:19:24 itojun 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(u_char
*user _U_
, const struct pcap_pkthdr
*h
,
48 register const u_char
*p
)
50 register u_int length
= h
->len
;
51 register u_int caplen
= h
->caplen
;
57 * Some printers want to get back at the link level addresses,
58 * and/or check that they're not walking off the end of the packet.
59 * Rather than pass them all the way down, we set these globals.
64 chdlc_print(p
, length
, caplen
);
73 chdlc_print(register const u_char
*p
, u_int length
, u_int caplen
)
78 if (caplen
< CHDLC_HDRLEN
) {
83 proto
= EXTRACT_16BITS(&p
[2]);
93 printf("0x%02x ", p
[0]);
96 printf("%d %04x: ", length
, proto
);
99 length
-= CHDLC_HDRLEN
;
100 ip
= (const struct ip
*)(p
+ CHDLC_HDRLEN
);
103 ip_print((const u_char
*)ip
, length
);
107 ip6_print((const u_char
*)ip
, length
);
110 case CHDLC_TYPE_SLARP
:
111 chdlc_slarp_print((const u_char
*)ip
, length
);
115 chdlc_cdp_print((const u_char
*)ip
, length
);
119 case ETHERTYPE_MPLS_MULTI
:
120 mpls_print((const u_char
*)(ip
), length
);
123 /* is the fudge byte set ? if yes lets skip a byte */
124 if (*(p
+CHDLC_HDRLEN
) == 0)
125 isoclns_print(p
+CHDLC_HDRLEN
+1, length
-1, length
-1, NULL
, NULL
);
127 isoclns_print(p
+CHDLC_HDRLEN
, length
, length
, NULL
, NULL
);
130 printf("unknown CHDLC protocol (0x%04x)", proto
);
134 default_print((const u_char
*)ip
, caplen
- CHDLC_HDRLEN
);
139 #define SLARP_REQUEST 0
140 #define SLARP_REPLY 1
141 #define SLARP_KEEPALIVE 2
156 } __attribute__((packed
));
161 chdlc_slarp_print(const u_char
*cp
, u_int length
)
163 const struct cisco_slarp
*slarp
;
165 if (length
< SLARP_LEN
) {
170 slarp
= (const struct cisco_slarp
*)cp
;
171 printf("SLARP (length: %u), ",length
);
172 switch (ntohl(slarp
->code
)) {
175 /* ok we do not know it - but lets at least dump it */
176 print_unknown_data(cp
+4,"\n\t",length
-4);
179 printf("reply %s/%s",
180 ipaddr_string(&slarp
->un
.addr
.addr
),
181 ipaddr_string(&slarp
->un
.addr
.mask
));
183 case SLARP_KEEPALIVE
:
184 printf("keepalive: mineseen=0x%08x yourseen=0x%08x ",
185 (u_int32_t
)ntohl(slarp
->un
.keep
.myseq
),
186 (u_int32_t
)ntohl(slarp
->un
.keep
.yourseq
));
187 printf("reliability=0x%04x t1=%d.%d",
188 ntohs(slarp
->un
.keep
.rel
), ntohs(slarp
->un
.keep
.t1
),
189 ntohs(slarp
->un
.keep
.t2
));
192 printf("0x%02x unknown", (u_int32_t
)ntohl(slarp
->code
));
194 print_unknown_data(cp
+4,"\n\t",length
-4);
198 if (SLARP_LEN
< length
&& vflag
)
199 printf(", (trailing junk: %d bytes)", length
- SLARP_LEN
);
201 print_unknown_data(cp
+4,"\n\t",length
-4);