]> The Tcpdump Group git mirrors - tcpdump/blob - print-chdlc.c
Bring in KAME IPv6 tcpdump. replaces esp/ah/isakmp decoder.
[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.1 1999-10-30 05:11:11 itojun Exp $ (LBL)";
26 #endif
27
28 #include <sys/param.h>
29 #include <sys/time.h>
30 #include <sys/socket.h>
31 #include <sys/file.h>
32 #include <sys/ioctl.h>
33
34 #if __STDC__
35 struct mbuf;
36 struct rtentry;
37 #endif
38 #include <net/if.h>
39
40 #include <netinet/in.h>
41 #include <netinet/in_systm.h>
42 #include <netinet/ip.h>
43 #include <netinet/if_ether.h>
44
45 #include <ctype.h>
46 #include <netdb.h>
47 #include <pcap.h>
48 #include <stdio.h>
49 #ifdef __bsdi__
50 #include <net/slcompress.h>
51 #include <net/if_ppp.h>
52 #endif
53
54 #include "interface.h"
55 #include "addrtoname.h"
56 #include "ppp.h"
57
58 /* XXX This goes somewhere else. */
59 #define CHDLC_HDRLEN 4
60 #define CHDLC_UNICAST 0x0f
61 #define CHDLC_BCAST 0x8f
62 #define CHDLC_TYPE_SLARP 0x8035
63 #define CHDLC_TYPE_CDP 0x2000
64
65 static void chdlc_slarp_print(const u_char *, u_int);
66
67 /* Standard CHDLC printer */
68 void
69 chdlc_if_print(u_char *user, const struct pcap_pkthdr *h,
70 register const u_char *p)
71 {
72 register u_int length = h->len;
73 register u_int caplen = h->caplen;
74 const struct ip *ip;
75 u_int proto;
76
77 ts_print(&h->ts);
78
79 if (caplen < CHDLC_HDRLEN) {
80 printf("[|chdlc]");
81 goto out;
82 }
83
84 /*
85 * Some printers want to get back at the link level addresses,
86 * and/or check that they're not walking off the end of the packet.
87 * Rather than pass them all the way down, we set these globals.
88 */
89 proto = ntohs(*(u_short *)&p[2]);
90 packetp = p;
91 snapend = p + caplen;
92
93 if (eflag) {
94 switch (p[0]) {
95 case CHDLC_UNICAST:
96 printf("unicast ");
97 break;
98 case CHDLC_BCAST:
99 printf("bcast ");
100 break;
101 default:
102 printf("0x%02x ", p[0]);
103 break;
104 }
105 printf("%d %04x: ", length, proto);
106 }
107
108 length -= CHDLC_HDRLEN;
109 ip = (struct ip *)(p + CHDLC_HDRLEN);
110 switch(proto) {
111 case ETHERTYPE_IP:
112 ip_print((const u_char *)ip, length);
113 break;
114 #ifdef INET6
115 case ETHERTYPE_IPV6:
116 ip6_print((const u_char *)ip, length);
117 break;
118 #endif
119 case CHDLC_TYPE_SLARP:
120 chdlc_slarp_print((const u_char *)ip, length);
121 break;
122 #if 0
123 case CHDLC_TYPE_CDP:
124 chdlc_cdp_print((const u_char *)ip, length);
125 break;
126 #endif
127 }
128 if (xflag)
129 default_print((const u_char *)ip, caplen - CHDLC_HDRLEN);
130 out:
131 putchar('\n');
132 }
133
134 struct cisco_slarp {
135 long code;
136 #define SLARP_REQUEST 0
137 #define SLARP_REPLY 1
138 #define SLARP_KEEPALIVE 2
139 union {
140 struct {
141 struct in_addr addr;
142 struct in_addr mask;
143 u_short unused[3];
144 } addr;
145 struct {
146 long myseq;
147 long yourseq;
148 short rel;
149 short t1;
150 short t2;
151 } keep;
152 } un;
153 };
154
155 #define SLARP_LEN 18
156
157 static void
158 chdlc_slarp_print(const u_char *cp, u_int length)
159 {
160 struct cisco_slarp *slarp;
161
162 if (length < SLARP_LEN) {
163 printf("[|slarp]");
164 return;
165 }
166
167 slarp = (struct cisco_slarp *)cp;
168 switch (ntohl(slarp->code)) {
169 case SLARP_REQUEST:
170 printf("slarp-request");
171 break;
172 case SLARP_REPLY:
173 printf("slarp-reply %s/%s",
174 ipaddr_string(&slarp->un.addr.addr),
175 ipaddr_string(&slarp->un.addr.mask));
176 break;
177 case SLARP_KEEPALIVE:
178 printf("slarp-keepalive my=0x%x your=0x%x ",
179 (u_int32_t)ntohl(slarp->un.keep.myseq),
180 (u_int32_t)ntohl(slarp->un.keep.yourseq));
181 printf("reliability=0x%04x t1=%d.%d",
182 ntohs(slarp->un.keep.rel), ntohs(slarp->un.keep.t1),
183 ntohs(slarp->un.keep.t2));
184 break;
185 default:
186 printf("slarp-0x%x unknown", (u_int32_t)ntohl(slarp->code));
187 break;
188 }
189
190 if (SLARP_LEN < length && vflag)
191 printf("(trailing junk: %d bytes)", length - SLARP_LEN);
192 }