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