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