Explicitly request literal mode after .Xr.
[netbsd-mini2440.git] / dist / tcpdump / print-chdlc.c
blob4455b36845c8fa5eed61cbe41ecd312a6093f131
1 /* $NetBSD$ */
3 /*
4 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
18 * written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
24 #include <sys/cdefs.h>
25 #ifndef lint
26 #if 0
27 static const char rcsid[] _U_ =
28 "@(#) Header: /tcpdump/master/tcpdump/print-chdlc.c,v 1.32.2.11 2005/11/29 08:57:10 hannes Exp (LBL)";
29 #else
30 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
31 #endif
32 #endif
34 #ifdef HAVE_CONFIG_H
35 #include "config.h"
36 #endif
38 #include <tcpdump-stdinc.h>
40 #include <pcap.h>
41 #include <stdio.h>
43 #include "interface.h"
44 #include "addrtoname.h"
45 #include "ethertype.h"
46 #include "extract.h"
47 #include "ppp.h"
48 #include "chdlc.h"
50 static void chdlc_slarp_print(const u_char *, u_int);
52 const struct tok chdlc_cast_values[] = {
53 { CHDLC_UNICAST, "unicast" },
54 { CHDLC_BCAST, "bcast" },
55 { 0, NULL}
59 /* Standard CHDLC printer */
60 u_int
61 chdlc_if_print(const struct pcap_pkthdr *h, register const u_char *p)
63 register u_int length = h->len;
64 register u_int caplen = h->caplen;
66 if (caplen < CHDLC_HDRLEN) {
67 printf("[|chdlc]");
68 return (caplen);
70 return (chdlc_print(p,length));
73 u_int
74 chdlc_print(register const u_char *p, u_int length) {
75 u_int proto;
77 proto = EXTRACT_16BITS(&p[2]);
78 if (eflag) {
79 printf("%s, ethertype %s (0x%04x), length %u: ",
80 tok2str(chdlc_cast_values, "0x%02x", p[0]),
81 tok2str(ethertype_values, "Unknown", proto),
82 proto,
83 length);
86 length -= CHDLC_HDRLEN;
87 p += CHDLC_HDRLEN;
89 switch (proto) {
90 case ETHERTYPE_IP:
91 ip_print(gndo, p, length);
92 break;
93 #ifdef INET6
94 case ETHERTYPE_IPV6:
95 ip6_print(p, length);
96 break;
97 #endif
98 case CHDLC_TYPE_SLARP:
99 chdlc_slarp_print(p, length);
100 break;
101 #if 0
102 case CHDLC_TYPE_CDP:
103 chdlc_cdp_print(p, length);
104 break;
105 #endif
106 case ETHERTYPE_MPLS:
107 case ETHERTYPE_MPLS_MULTI:
108 mpls_print(p, length);
109 break;
110 case ETHERTYPE_ISO:
111 /* is the fudge byte set ? lets verify by spotting ISO headers */
112 if (*(p+1) == 0x81 ||
113 *(p+1) == 0x82 ||
114 *(p+1) == 0x83)
115 isoclns_print(p+1, length-1, length-1);
116 else
117 isoclns_print(p, length, length);
118 break;
119 default:
120 if (!eflag)
121 printf("unknown CHDLC protocol (0x%04x)", proto);
122 break;
125 return (CHDLC_HDRLEN);
129 * The fixed-length portion of a SLARP packet.
131 struct cisco_slarp {
132 u_int8_t code[4];
133 #define SLARP_REQUEST 0
134 #define SLARP_REPLY 1
135 #define SLARP_KEEPALIVE 2
136 union {
137 struct {
138 u_int8_t addr[4];
139 u_int8_t mask[4];
140 } addr;
141 struct {
142 u_int8_t myseq[4];
143 u_int8_t yourseq[4];
144 u_int8_t rel[2];
145 } keep;
146 } un;
149 #define SLARP_MIN_LEN 14
150 #define SLARP_MAX_LEN 18
152 static void
153 chdlc_slarp_print(const u_char *cp, u_int length)
155 const struct cisco_slarp *slarp;
156 u_int sec,min,hrs,days;
158 printf("SLARP (length: %u), ",length);
159 if (length < SLARP_MIN_LEN)
160 goto trunc;
162 slarp = (const struct cisco_slarp *)cp;
163 TCHECK2(*slarp, SLARP_MIN_LEN);
164 switch (EXTRACT_32BITS(&slarp->code)) {
165 case SLARP_REQUEST:
166 printf("request");
168 * At least according to William "Chops" Westfield's
169 * message in
171 * http://www.nethelp.no/net/cisco-hdlc.txt
173 * the address and mask aren't used in requests -
174 * they're just zero.
176 break;
177 case SLARP_REPLY:
178 printf("reply %s/%s",
179 ipaddr_string(&slarp->un.addr.addr),
180 ipaddr_string(&slarp->un.addr.mask));
181 break;
182 case SLARP_KEEPALIVE:
183 printf("keepalive: mineseen=0x%08x, yourseen=0x%08x, reliability=0x%04x",
184 EXTRACT_32BITS(&slarp->un.keep.myseq),
185 EXTRACT_32BITS(&slarp->un.keep.yourseq),
186 EXTRACT_16BITS(&slarp->un.keep.rel));
188 if (length >= SLARP_MAX_LEN) { /* uptime-stamp is optional */
189 cp += SLARP_MIN_LEN;
190 if (!TTEST2(*cp, 4))
191 goto trunc;
192 sec = EXTRACT_32BITS(cp) / 1000;
193 min = sec / 60; sec -= min * 60;
194 hrs = min / 60; min -= hrs * 60;
195 days = hrs / 24; hrs -= days * 24;
196 printf(", link uptime=%ud%uh%um%us",days,hrs,min,sec);
198 break;
199 default:
200 printf("0x%02x unknown", EXTRACT_32BITS(&slarp->code));
201 if (vflag <= 1)
202 print_unknown_data(cp+4,"\n\t",length-4);
203 break;
206 if (SLARP_MAX_LEN < length && vflag)
207 printf(", (trailing junk: %d bytes)", length - SLARP_MAX_LEN);
208 if (vflag > 1)
209 print_unknown_data(cp+4,"\n\t",length-4);
210 return;
212 trunc:
213 printf("[|slarp]");
218 * Local Variables:
219 * c-style: whitesmith
220 * c-basic-offset: 8
221 * End: