]> The Tcpdump Group git mirrors - tcpdump/blob - print-sll.c
We no longer use "packetp" for anything, so eliminate it. (If any
[tcpdump] / print-sll.c
1 /*
2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 */
21 #ifndef lint
22 static const char rcsid[] =
23 "@(#) $Header: /tcpdump/master/tcpdump/print-sll.c,v 1.10 2002-12-18 08:53:24 guy Exp $ (LBL)";
24 #endif
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include <tcpdump-stdinc.h>
31
32 #include <stdio.h>
33 #include <string.h>
34 #include <pcap.h>
35
36 #include "interface.h"
37 #include "addrtoname.h"
38 #include "ethertype.h"
39
40 #include "ether.h"
41 #include "sll.h"
42
43 static inline void
44 sll_print(register const struct sll_header *sllp, u_int length)
45 {
46 u_short halen;
47
48 switch (ntohs(sllp->sll_pkttype)) {
49
50 case LINUX_SLL_HOST:
51 (void)printf("< ");
52 break;
53
54 case LINUX_SLL_BROADCAST:
55 (void)printf("B ");
56 break;
57
58 case LINUX_SLL_MULTICAST:
59 (void)printf("M ");
60 break;
61
62 case LINUX_SLL_OTHERHOST:
63 (void)printf("P ");
64 break;
65
66 case LINUX_SLL_OUTGOING:
67 (void)printf("> ");
68 break;
69
70 default:
71 (void)printf("? ");
72 break;
73 }
74
75 /*
76 * XXX - check the link-layer address type value?
77 * For now, we just assume 6 means Ethernet.
78 * XXX - print others as strings of hex?
79 */
80 halen = ntohs(sllp->sll_halen);
81 if (halen == 6)
82 (void)printf("%s ", etheraddr_string(sllp->sll_addr));
83
84 if (!qflag)
85 (void)printf("%s ", etherproto_string(sllp->sll_protocol));
86 (void)printf("%d: ", length);
87 }
88
89 /*
90 * This is the top level routine of the printer. 'p' points to the
91 * Linux "cooked capture" header of the packet, 'h->ts' is the timestamp,
92 * 'h->length' is the length of the packet off the wire, and 'h->caplen'
93 * is the number of bytes actually captured.
94 */
95 void
96 sll_if_print(u_char *user _U_, const struct pcap_pkthdr *h, const u_char *p)
97 {
98 u_int caplen = h->caplen;
99 u_int length = h->len;
100 register const struct sll_header *sllp;
101 u_short ether_type;
102 u_short extracted_ethertype;
103
104 ++infodelay;
105 ts_print(&h->ts);
106
107 if (caplen < SLL_HDR_LEN) {
108 /*
109 * XXX - this "can't happen" because "pcap-linux.c" always
110 * adds this many bytes of header to every packet in a
111 * cooked socket capture.
112 */
113 printf("[|sll]");
114 goto out;
115 }
116
117 sllp = (const struct sll_header *)p;
118
119 if (eflag)
120 sll_print(sllp, length);
121
122 /*
123 * Some printers want to check that they're not walking off the
124 * end of the packet.
125 * Rather than pass it all the way down, we set this global.
126 */
127 snapend = p + caplen;
128
129 length -= SLL_HDR_LEN;
130 caplen -= SLL_HDR_LEN;
131 p += SLL_HDR_LEN;
132
133 ether_type = ntohs(sllp->sll_protocol);
134
135 /*
136 * Is it (gag) an 802.3 encapsulation, or some non-Ethernet
137 * packet type?
138 */
139 extracted_ethertype = 0;
140 if (ether_type <= ETHERMTU) {
141 /*
142 * Yes - what type is it?
143 */
144 switch (ether_type) {
145
146 case LINUX_SLL_P_802_3:
147 /*
148 * Ethernet_802.3 IPX frame.
149 */
150 ipx_print(p, length);
151 break;
152
153 case LINUX_SLL_P_802_2:
154 /*
155 * 802.2.
156 * Try to print the LLC-layer header & higher layers.
157 */
158 if (llc_print(p, length, caplen, NULL, NULL,
159 &extracted_ethertype) == 0)
160 goto unknown; /* unknown LLC type */
161 break;
162
163 default:
164 unknown:
165 /* ether_type not known, print raw packet */
166 if (!eflag)
167 sll_print(sllp, length + SLL_HDR_LEN);
168 if (extracted_ethertype) {
169 printf("(LLC %s) ",
170 etherproto_string(htons(extracted_ethertype)));
171 }
172 if (!xflag && !qflag)
173 default_print(p, caplen);
174 break;
175 }
176 } else if (ether_encap_print(ether_type, p, length, caplen,
177 &extracted_ethertype) == 0) {
178 /* ether_type not known, print raw packet */
179 if (!eflag)
180 sll_print(sllp, length + SLL_HDR_LEN);
181 if (!xflag && !qflag)
182 default_print(p, caplen);
183 }
184 if (xflag)
185 default_print(p, caplen);
186 out:
187 putchar('\n');
188 --infodelay;
189 if (infoprint)
190 info(0);
191 }