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