]> The Tcpdump Group git mirrors - tcpdump/blob - print-chdlc.c
(token_if_print): remove unused variable
[tcpdump] / print-chdlc.c
1 /* maybe it should be merged into print-ppp.c */
2 /*
3 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
4 * The Regents of the University of California. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that: (1) source code distributions
8 * retain the above copyright notice and this paragraph in its entirety, (2)
9 * distributions including binary code include the above copyright notice and
10 * this paragraph in its entirety in the documentation or other materials
11 * provided with the distribution, and (3) all advertising materials mentioning
12 * features or use of this software display the following acknowledgement:
13 * ``This product includes software developed by the University of California,
14 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
15 * the University nor the names of its contributors may be used to endorse
16 * or promote products derived from this software without specific prior
17 * written permission.
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 */
22
23 #ifndef lint
24 static const char rcsid[] =
25 "@(#) $Header: /tcpdump/master/tcpdump/print-chdlc.c,v 1.4 2000-07-01 03:39:01 assar Exp $ (LBL)";
26 #endif
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include <sys/param.h>
33 #include <sys/time.h>
34 #include <sys/socket.h>
35 #include <sys/file.h>
36 #include <sys/ioctl.h>
37
38 struct mbuf;
39 struct rtentry;
40 #include <net/if.h>
41
42 #include <netinet/in.h>
43 #include <netinet/in_systm.h>
44 #include <netinet/ip.h>
45 #include <netinet/if_ether.h>
46
47 #include <ctype.h>
48 #include <netdb.h>
49 #include <pcap.h>
50 #include <stdio.h>
51 #ifdef __bsdi__
52 #include <net/slcompress.h>
53 #include <net/if_ppp.h>
54 #endif
55
56 #include "interface.h"
57 #include "addrtoname.h"
58 #include "ppp.h"
59
60 /* XXX This goes somewhere else. */
61 #define CHDLC_HDRLEN 4
62 #define CHDLC_UNICAST 0x0f
63 #define CHDLC_BCAST 0x8f
64 #define CHDLC_TYPE_SLARP 0x8035
65 #define CHDLC_TYPE_CDP 0x2000
66
67 static void chdlc_slarp_print(const u_char *, u_int);
68
69 /* Standard CHDLC printer */
70 void
71 chdlc_if_print(u_char *user, const struct pcap_pkthdr *h,
72 register const u_char *p)
73 {
74 register u_int length = h->len;
75 register u_int caplen = h->caplen;
76 const struct ip *ip;
77 u_int proto;
78
79 ts_print(&h->ts);
80
81 if (caplen < CHDLC_HDRLEN) {
82 printf("[|chdlc]");
83 goto out;
84 }
85
86 /*
87 * Some printers want to get back at the link level addresses,
88 * and/or check that they're not walking off the end of the packet.
89 * Rather than pass them all the way down, we set these globals.
90 */
91 proto = ntohs(*(u_short *)&p[2]);
92 packetp = p;
93 snapend = p + caplen;
94
95 if (eflag) {
96 switch (p[0]) {
97 case CHDLC_UNICAST:
98 printf("unicast ");
99 break;
100 case CHDLC_BCAST:
101 printf("bcast ");
102 break;
103 default:
104 printf("0x%02x ", p[0]);
105 break;
106 }
107 printf("%d %04x: ", length, proto);
108 }
109
110 length -= CHDLC_HDRLEN;
111 ip = (struct ip *)(p + CHDLC_HDRLEN);
112 switch (proto) {
113 case ETHERTYPE_IP:
114 ip_print((const u_char *)ip, length);
115 break;
116 #ifdef INET6
117 case ETHERTYPE_IPV6:
118 ip6_print((const u_char *)ip, length);
119 break;
120 #endif
121 case CHDLC_TYPE_SLARP:
122 chdlc_slarp_print((const u_char *)ip, length);
123 break;
124 #if 0
125 case CHDLC_TYPE_CDP:
126 chdlc_cdp_print((const u_char *)ip, length);
127 break;
128 #endif
129 }
130 if (xflag)
131 default_print((const u_char *)ip, caplen - CHDLC_HDRLEN);
132 out:
133 putchar('\n');
134 }
135
136 struct cisco_slarp {
137 long code;
138 #define SLARP_REQUEST 0
139 #define SLARP_REPLY 1
140 #define SLARP_KEEPALIVE 2
141 union {
142 struct {
143 struct in_addr addr;
144 struct in_addr mask;
145 u_short unused[3];
146 } addr;
147 struct {
148 long myseq;
149 long yourseq;
150 short rel;
151 short t1;
152 short t2;
153 } keep;
154 } un;
155 };
156
157 #define SLARP_LEN 18
158
159 static void
160 chdlc_slarp_print(const u_char *cp, u_int length)
161 {
162 struct cisco_slarp *slarp;
163
164 if (length < SLARP_LEN) {
165 printf("[|slarp]");
166 return;
167 }
168
169 slarp = (struct cisco_slarp *)cp;
170 switch (ntohl(slarp->code)) {
171 case SLARP_REQUEST:
172 printf("slarp-request");
173 break;
174 case SLARP_REPLY:
175 printf("slarp-reply %s/%s",
176 ipaddr_string(&slarp->un.addr.addr),
177 ipaddr_string(&slarp->un.addr.mask));
178 break;
179 case SLARP_KEEPALIVE:
180 printf("slarp-keepalive my=0x%x your=0x%x ",
181 (u_int32_t)ntohl(slarp->un.keep.myseq),
182 (u_int32_t)ntohl(slarp->un.keep.yourseq));
183 printf("reliability=0x%04x t1=%d.%d",
184 ntohs(slarp->un.keep.rel), ntohs(slarp->un.keep.t1),
185 ntohs(slarp->un.keep.t2));
186 break;
187 default:
188 printf("slarp-0x%x unknown", (u_int32_t)ntohl(slarp->code));
189 break;
190 }
191
192 if (SLARP_LEN < length && vflag)
193 printf("(trailing junk: %d bytes)", length - SLARP_LEN);
194 }