Explicitly request literal mode after .Xr.
[netbsd-mini2440.git] / dist / tcpdump / print-sll.c
blob4f2ed5d7440773ed697ce54c6aa52f83bd10a993
1 /* $NetBSD$ */
3 /*
4 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 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.
23 #include <sys/cdefs.h>
24 #ifndef lint
25 #if 0
26 static const char rcsid[] _U_ =
27 "@(#) Header: /tcpdump/master/tcpdump/print-sll.c,v 1.16.2.3 2005/11/13 12:13:00 guy Exp (LBL)";
28 #else
29 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
30 #endif
31 #endif
33 #ifdef HAVE_CONFIG_H
34 #include "config.h"
35 #endif
37 #include <tcpdump-stdinc.h>
39 #include <stdio.h>
40 #include <string.h>
41 #include <pcap.h>
43 #include "interface.h"
44 #include "addrtoname.h"
45 #include "ethertype.h"
46 #include "extract.h"
48 #include "ether.h"
49 #include "sll.h"
51 const struct tok sll_pkttype_values[] = {
52 { LINUX_SLL_HOST, "In" },
53 { LINUX_SLL_BROADCAST, "B" },
54 { LINUX_SLL_MULTICAST, "M" },
55 { LINUX_SLL_OTHERHOST, "P" },
56 { LINUX_SLL_OUTGOING, "Out" },
57 { 0, NULL}
60 static inline void
61 sll_print(register const struct sll_header *sllp, u_int length)
63 u_short ether_type;
65 printf("%3s ",tok2str(sll_pkttype_values,"?",EXTRACT_16BITS(&sllp->sll_pkttype)));
68 * XXX - check the link-layer address type value?
69 * For now, we just assume 6 means Ethernet.
70 * XXX - print others as strings of hex?
72 if (EXTRACT_16BITS(&sllp->sll_halen) == 6)
73 (void)printf("%s ", etheraddr_string(sllp->sll_addr));
75 if (!qflag) {
76 ether_type = EXTRACT_16BITS(&sllp->sll_protocol);
78 if (ether_type <= ETHERMTU) {
80 * Not an Ethernet type; what type is it?
82 switch (ether_type) {
84 case LINUX_SLL_P_802_3:
86 * Ethernet_802.3 IPX frame.
88 (void)printf("802.3");
89 break;
91 case LINUX_SLL_P_802_2:
93 * 802.2.
95 (void)printf("802.3");
96 break;
98 default:
100 * What is it?
102 (void)printf("ethertype Unknown (0x%04x)",
103 ether_type);
104 break;
106 } else {
107 (void)printf("ethertype %s (0x%04x)",
108 tok2str(ethertype_values, "Unknown", ether_type),
109 ether_type);
111 (void)printf(", length %u: ", length);
116 * This is the top level routine of the printer. 'p' points to the
117 * Linux "cooked capture" header of the packet, 'h->ts' is the timestamp,
118 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
119 * is the number of bytes actually captured.
121 u_int
122 sll_if_print(const struct pcap_pkthdr *h, const u_char *p)
124 u_int caplen = h->caplen;
125 u_int length = h->len;
126 register const struct sll_header *sllp;
127 u_short ether_type;
128 u_short extracted_ethertype;
130 if (caplen < SLL_HDR_LEN) {
132 * XXX - this "can't happen" because "pcap-linux.c" always
133 * adds this many bytes of header to every packet in a
134 * cooked socket capture.
136 printf("[|sll]");
137 return (caplen);
140 sllp = (const struct sll_header *)p;
142 if (eflag)
143 sll_print(sllp, length);
146 * Go past the cooked-mode header.
148 length -= SLL_HDR_LEN;
149 caplen -= SLL_HDR_LEN;
150 p += SLL_HDR_LEN;
152 ether_type = ntohs(sllp->sll_protocol);
155 * Is it (gag) an 802.3 encapsulation, or some non-Ethernet
156 * packet type?
158 if (ether_type <= ETHERMTU) {
160 * Yes - what type is it?
162 switch (ether_type) {
164 case LINUX_SLL_P_802_3:
166 * Ethernet_802.3 IPX frame.
168 ipx_print(p, length);
169 break;
171 case LINUX_SLL_P_802_2:
173 * 802.2.
174 * Try to print the LLC-layer header & higher layers.
176 if (llc_print(p, length, caplen, NULL, NULL,
177 &extracted_ethertype) == 0)
178 goto unknown; /* unknown LLC type */
179 break;
181 default:
182 extracted_ethertype = 0;
183 /*FALLTHROUGH*/
185 unknown:
186 /* ether_type not known, print raw packet */
187 if (!eflag)
188 sll_print(sllp, length + SLL_HDR_LEN);
189 if (extracted_ethertype) {
190 printf("(LLC %s) ",
191 etherproto_string(htons(extracted_ethertype)));
193 if (!suppress_default_print)
194 default_print(p, caplen);
195 break;
197 } else if (ether_encap_print(ether_type, p, length, caplen,
198 &extracted_ethertype) == 0) {
199 /* ether_type not known, print raw packet */
200 if (!eflag)
201 sll_print(sllp, length + SLL_HDR_LEN);
202 if (!suppress_default_print)
203 default_print(p, caplen);
206 return (SLL_HDR_LEN);