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