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.8 2002-08-01 08:53:28 risso Exp $ (LBL)";
30 #include <tcpdump-stdinc.h>
36 #include "interface.h"
37 #include "addrtoname.h"
38 #include "ethertype.h"
44 sll_print(register const struct sll_header
*sllp
, u_int length
)
48 switch (ntohs(sllp
->sll_pkttype
)) {
54 case LINUX_SLL_BROADCAST
:
58 case LINUX_SLL_MULTICAST
:
62 case LINUX_SLL_OTHERHOST
:
66 case LINUX_SLL_OUTGOING
:
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?
80 halen
= ntohs(sllp
->sll_halen
);
82 (void)printf("%s ", etheraddr_string(sllp
->sll_addr
));
85 (void)printf("%s ", etherproto_string(sllp
->sll_protocol
));
86 (void)printf("%d: ", length
);
90 * This is the top level routine of the printer. 'p' is the points
91 * to the ether header of the packet, 'h->tv' 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.
96 sll_if_print(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*p
)
98 u_int caplen
= h
->caplen
;
99 u_int length
= h
->len
;
100 register const struct sll_header
*sllp
;
102 struct ether_header ehdr
;
104 u_short extracted_ethertype
;
109 if (caplen
< SLL_HDR_LEN
) {
111 * XXX - this "can't happen" because "pcap-linux.c" always
112 * adds this many bytes of header to every packet in a
113 * cooked socket capture.
119 sllp
= (const struct sll_header
*)p
;
122 * Fake up an Ethernet header for the benefit of printers that
123 * insist on "packetp" pointing to an Ethernet header.
125 pkttype
= ntohs(sllp
->sll_pkttype
);
127 /* The source address is in the packet header */
128 memcpy(ehdr
.ether_shost
, sllp
->sll_addr
, ETHER_ADDR_LEN
);
130 if (pkttype
!= LINUX_SLL_OUTGOING
) {
132 * We received this packet.
134 * We don't know the destination address, so
135 * we fake it - all 0's except that the
136 * bottommost bit of the bottommost octet
137 * is set for a unicast packet, all 0's except
138 * that the bottommost bit of the uppermost
139 * octet is set for a multicast packet, all
140 * 1's for a broadcast packet.
142 if (pkttype
== LINUX_SLL_BROADCAST
)
143 memset(ehdr
.ether_dhost
, 0xFF, ETHER_ADDR_LEN
);
145 memset(ehdr
.ether_dhost
, 0, ETHER_ADDR_LEN
);
146 if (pkttype
== LINUX_SLL_MULTICAST
)
147 ehdr
.ether_dhost
[0] = 1;
149 ehdr
.ether_dhost
[ETHER_ADDR_LEN
-1] = 1;
153 * We sent this packet; we don't know whether it's
154 * broadcast, multicast, or unicast, so just make
155 * the destination address all 0's.
157 memset(ehdr
.ether_dhost
, 0, ETHER_ADDR_LEN
);
161 sll_print(sllp
, length
);
164 * Some printers want to get back at the ethernet addresses,
165 * and/or check that they're not walking off the end of the packet.
166 * Rather than pass them all the way down, we set these globals.
168 snapend
= p
+ caplen
;
170 * Actually, the only printers that use packetp are print-arp.c
171 * and print-bootp.c, and they assume that packetp points to an
172 * Ethernet header. The right thing to do is to fix them to know
173 * which link type is in use when they excavate. XXX
175 packetp
= (u_char
*)&ehdr
;
177 length
-= SLL_HDR_LEN
;
178 caplen
-= SLL_HDR_LEN
;
181 ether_type
= ntohs(sllp
->sll_protocol
);
184 * Is it (gag) an 802.3 encapsulation, or some non-Ethernet
187 extracted_ethertype
= 0;
188 if (ether_type
<= ETHERMTU
) {
190 * Yes - what type is it?
192 switch (ether_type
) {
194 case LINUX_SLL_P_802_3
:
196 * Ethernet_802.3 IPX frame.
198 ipx_print(p
, length
);
201 case LINUX_SLL_P_802_2
:
204 * Try to print the LLC-layer header & higher layers.
206 if (llc_print(p
, length
, caplen
, ESRC(&ehdr
),
207 EDST(&ehdr
), &extracted_ethertype
) == 0)
208 goto unknown
; /* unknown LLC type */
213 /* ether_type not known, print raw packet */
215 sll_print(sllp
, length
+ SLL_HDR_LEN
);
216 if (extracted_ethertype
) {
218 etherproto_string(htons(extracted_ethertype
)));
220 if (!xflag
&& !qflag
)
221 default_print(p
, caplen
);
224 } else if (ether_encap_print(ether_type
, p
, length
, caplen
,
225 &extracted_ethertype
) == 0) {
226 /* ether_type not known, print raw packet */
228 sll_print(sllp
, length
+ SLL_HDR_LEN
);
229 if (!xflag
&& !qflag
)
230 default_print(p
, caplen
);
233 default_print(p
, caplen
);