2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
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
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.
22 static const char rcsid
[] =
23 "@(#) $Header: /tcpdump/master/tcpdump/print-sll.c,v 1.6 2001-07-05 18:54:18 guy Exp $ (LBL)";
30 #include <sys/param.h>
32 #include <sys/socket.h>
37 #include <netinet/in.h>
43 #include "interface.h"
44 #include "addrtoname.h"
45 #include "ethertype.h"
51 sll_print(register const struct sll_header
*sllp
, u_int length
)
55 switch (ntohs(sllp
->sll_pkttype
)) {
61 case LINUX_SLL_BROADCAST
:
65 case LINUX_SLL_MULTICAST
:
69 case LINUX_SLL_OTHERHOST
:
73 case LINUX_SLL_OUTGOING
:
83 * XXX - check the link-layer address type value?
84 * For now, we just assume 6 means Ethernet.
85 * XXX - print others as strings of hex?
87 halen
= ntohs(sllp
->sll_halen
);
89 (void)printf("%s ", etheraddr_string(sllp
->sll_addr
));
92 (void)printf("%s ", etherproto_string(sllp
->sll_protocol
));
93 (void)printf("%d: ", length
);
97 * This is the top level routine of the printer. 'p' is the points
98 * to the ether header of the packet, 'h->tv' is the timestamp,
99 * 'h->length' is the length of the packet off the wire, and 'h->caplen'
100 * is the number of bytes actually captured.
103 sll_if_print(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*p
)
105 u_int caplen
= h
->caplen
;
106 u_int length
= h
->len
;
107 register const struct sll_header
*sllp
;
109 struct ether_header ehdr
;
111 u_short extracted_ethertype
;
116 if (caplen
< SLL_HDR_LEN
) {
118 * XXX - this "can't happen" because "pcap-linux.c" always
119 * adds this many bytes of header to every packet in a
120 * cooked socket capture.
126 sllp
= (const struct sll_header
*)p
;
129 * Fake up an Ethernet header for the benefit of printers that
130 * insist on "packetp" pointing to an Ethernet header.
132 pkttype
= ntohs(sllp
->sll_pkttype
);
134 /* The source address is in the packet header */
135 memcpy(ehdr
.ether_shost
, sllp
->sll_addr
, ETHER_ADDR_LEN
);
137 if (pkttype
!= LINUX_SLL_OUTGOING
) {
139 * We received this packet.
141 * We don't know the destination address, so
142 * we fake it - all 0's except that the
143 * bottommost bit of the bottommost octet
144 * is set for a unicast packet, all 0's except
145 * that the bottommost bit of the uppermost
146 * octet is set for a multicast packet, all
147 * 1's for a broadcast packet.
149 if (pkttype
== LINUX_SLL_BROADCAST
)
150 memset(ehdr
.ether_dhost
, 0xFF, ETHER_ADDR_LEN
);
152 memset(ehdr
.ether_dhost
, 0, ETHER_ADDR_LEN
);
153 if (pkttype
== LINUX_SLL_MULTICAST
)
154 ehdr
.ether_dhost
[0] = 1;
156 ehdr
.ether_dhost
[ETHER_ADDR_LEN
-1] = 1;
160 * We sent this packet; we don't know whether it's
161 * broadcast, multicast, or unicast, so just make
162 * the destination address all 0's.
164 memset(ehdr
.ether_dhost
, 0, ETHER_ADDR_LEN
);
168 sll_print(sllp
, length
);
171 * Some printers want to get back at the ethernet addresses,
172 * and/or check that they're not walking off the end of the packet.
173 * Rather than pass them all the way down, we set these globals.
175 snapend
= p
+ caplen
;
177 * Actually, the only printers that use packetp are print-arp.c
178 * and print-bootp.c, and they assume that packetp points to an
179 * Ethernet header. The right thing to do is to fix them to know
180 * which link type is in use when they excavate. XXX
182 packetp
= (u_char
*)&ehdr
;
184 length
-= SLL_HDR_LEN
;
185 caplen
-= SLL_HDR_LEN
;
188 ether_type
= ntohs(sllp
->sll_protocol
);
191 * Is it (gag) an 802.3 encapsulation, or some non-Ethernet
194 extracted_ethertype
= 0;
195 if (ether_type
<= ETHERMTU
) {
197 * Yes - what type is it?
199 switch (ether_type
) {
201 case LINUX_SLL_P_802_3
:
203 * Ethernet_802.3 IPX frame.
205 ipx_print(p
, length
);
208 case LINUX_SLL_P_802_2
:
211 * Try to print the LLC-layer header & higher layers.
213 if (llc_print(p
, length
, caplen
, ESRC(&ehdr
),
214 EDST(&ehdr
), &extracted_ethertype
) == 0)
215 goto unknown
; /* unknown LLC type */
220 /* ether_type not known, print raw packet */
222 sll_print(sllp
, length
+ SLL_HDR_LEN
);
223 if (extracted_ethertype
) {
225 etherproto_string(htons(extracted_ethertype
)));
227 if (!xflag
&& !qflag
)
228 default_print(p
, caplen
);
231 } else if (ether_encap_print(ether_type
, p
, length
, caplen
,
232 &extracted_ethertype
) == 0) {
233 /* ether_type not known, print raw packet */
235 sll_print(sllp
, length
+ SLL_HDR_LEN
);
236 if (!xflag
&& !qflag
)
237 default_print(p
, caplen
);
240 default_print(p
, caplen
);