]> The Tcpdump Group git mirrors - tcpdump/blob - print-chdlc.c
Change -z command help text to -z postrotate-command
[tcpdump] / print-chdlc.c
1 /*
2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
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
16 * written permission.
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.
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include <netdissect-stdinc.h>
27
28 #include "netdissect.h"
29 #include "addrtoname.h"
30 #include "ethertype.h"
31 #include "extract.h"
32 #include "chdlc.h"
33
34 static void chdlc_slarp_print(netdissect_options *, const u_char *, u_int);
35
36 static const struct tok chdlc_cast_values[] = {
37 { CHDLC_UNICAST, "unicast" },
38 { CHDLC_BCAST, "bcast" },
39 { 0, NULL}
40 };
41
42
43 /* Standard CHDLC printer */
44 u_int
45 chdlc_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p)
46 {
47 register u_int length = h->len;
48 register u_int caplen = h->caplen;
49
50 if (caplen < CHDLC_HDRLEN) {
51 ND_PRINT((ndo, "[|chdlc]"));
52 return (caplen);
53 }
54 return (chdlc_print(ndo, p,length));
55 }
56
57 u_int
58 chdlc_print(netdissect_options *ndo, register const u_char *p, u_int length)
59 {
60 u_int proto;
61
62 proto = EXTRACT_16BITS(&p[2]);
63 if (ndo->ndo_eflag) {
64 ND_PRINT((ndo, "%s, ethertype %s (0x%04x), length %u: ",
65 tok2str(chdlc_cast_values, "0x%02x", p[0]),
66 tok2str(ethertype_values, "Unknown", proto),
67 proto,
68 length));
69 }
70
71 length -= CHDLC_HDRLEN;
72 p += CHDLC_HDRLEN;
73
74 switch (proto) {
75 case ETHERTYPE_IP:
76 ip_print(ndo, p, length);
77 break;
78 case ETHERTYPE_IPV6:
79 ip6_print(ndo, p, length);
80 break;
81 case CHDLC_TYPE_SLARP:
82 chdlc_slarp_print(ndo, p, length);
83 break;
84 #if 0
85 case CHDLC_TYPE_CDP:
86 chdlc_cdp_print(p, length);
87 break;
88 #endif
89 case ETHERTYPE_MPLS:
90 case ETHERTYPE_MPLS_MULTI:
91 mpls_print(ndo, p, length);
92 break;
93 case ETHERTYPE_ISO:
94 /* is the fudge byte set ? lets verify by spotting ISO headers */
95 if (*(p+1) == 0x81 ||
96 *(p+1) == 0x82 ||
97 *(p+1) == 0x83)
98 isoclns_print(ndo, p + 1, length - 1, length - 1);
99 else
100 isoclns_print(ndo, p, length, length);
101 break;
102 default:
103 if (!ndo->ndo_eflag)
104 ND_PRINT((ndo, "unknown CHDLC protocol (0x%04x)", proto));
105 break;
106 }
107
108 return (CHDLC_HDRLEN);
109 }
110
111 /*
112 * The fixed-length portion of a SLARP packet.
113 */
114 struct cisco_slarp {
115 uint8_t code[4];
116 #define SLARP_REQUEST 0
117 #define SLARP_REPLY 1
118 #define SLARP_KEEPALIVE 2
119 union {
120 struct {
121 uint8_t addr[4];
122 uint8_t mask[4];
123 } addr;
124 struct {
125 uint8_t myseq[4];
126 uint8_t yourseq[4];
127 uint8_t rel[2];
128 } keep;
129 } un;
130 };
131
132 #define SLARP_MIN_LEN 14
133 #define SLARP_MAX_LEN 18
134
135 static void
136 chdlc_slarp_print(netdissect_options *ndo, const u_char *cp, u_int length)
137 {
138 const struct cisco_slarp *slarp;
139 u_int sec,min,hrs,days;
140
141 ND_PRINT((ndo, "SLARP (length: %u), ",length));
142 if (length < SLARP_MIN_LEN)
143 goto trunc;
144
145 slarp = (const struct cisco_slarp *)cp;
146 ND_TCHECK2(*slarp, SLARP_MIN_LEN);
147 switch (EXTRACT_32BITS(&slarp->code)) {
148 case SLARP_REQUEST:
149 ND_PRINT((ndo, "request"));
150 /*
151 * At least according to William "Chops" Westfield's
152 * message in
153 *
154 * http://www.nethelp.no/net/cisco-hdlc.txt
155 *
156 * the address and mask aren't used in requests -
157 * they're just zero.
158 */
159 break;
160 case SLARP_REPLY:
161 ND_PRINT((ndo, "reply %s/%s",
162 ipaddr_string(ndo, &slarp->un.addr.addr),
163 ipaddr_string(ndo, &slarp->un.addr.mask)));
164 break;
165 case SLARP_KEEPALIVE:
166 ND_PRINT((ndo, "keepalive: mineseen=0x%08x, yourseen=0x%08x, reliability=0x%04x",
167 EXTRACT_32BITS(&slarp->un.keep.myseq),
168 EXTRACT_32BITS(&slarp->un.keep.yourseq),
169 EXTRACT_16BITS(&slarp->un.keep.rel)));
170
171 if (length >= SLARP_MAX_LEN) { /* uptime-stamp is optional */
172 cp += SLARP_MIN_LEN;
173 ND_TCHECK2(*cp, 4);
174 sec = EXTRACT_32BITS(cp) / 1000;
175 min = sec / 60; sec -= min * 60;
176 hrs = min / 60; min -= hrs * 60;
177 days = hrs / 24; hrs -= days * 24;
178 ND_PRINT((ndo, ", link uptime=%ud%uh%um%us",days,hrs,min,sec));
179 }
180 break;
181 default:
182 ND_PRINT((ndo, "0x%02x unknown", EXTRACT_32BITS(&slarp->code)));
183 if (ndo->ndo_vflag <= 1)
184 print_unknown_data(ndo,cp+4,"\n\t",length-4);
185 break;
186 }
187
188 if (SLARP_MAX_LEN < length && ndo->ndo_vflag)
189 ND_PRINT((ndo, ", (trailing junk: %d bytes)", length - SLARP_MAX_LEN));
190 if (ndo->ndo_vflag > 1)
191 print_unknown_data(ndo,cp+4,"\n\t",length-4);
192 return;
193
194 trunc:
195 ND_PRINT((ndo, "[|slarp]"));
196 }
197
198
199 /*
200 * Local Variables:
201 * c-style: whitesmith
202 * c-basic-offset: 8
203 * End:
204 */