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