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.7 2002-06-01 23:50:33 guy Exp $ (LBL)";
30 #include <sys/param.h>
32 #include <sys/socket.h>
34 #include <netinet/in.h>
40 #include "interface.h"
41 #include "addrtoname.h"
42 #include "ethertype.h"
48 sll_print(register const struct sll_header
*sllp
, u_int length
)
52 switch (ntohs(sllp
->sll_pkttype
)) {
58 case LINUX_SLL_BROADCAST
:
62 case LINUX_SLL_MULTICAST
:
66 case LINUX_SLL_OTHERHOST
:
70 case LINUX_SLL_OUTGOING
:
80 * XXX - check the link-layer address type value?
81 * For now, we just assume 6 means Ethernet.
82 * XXX - print others as strings of hex?
84 halen
= ntohs(sllp
->sll_halen
);
86 (void)printf("%s ", etheraddr_string(sllp
->sll_addr
));
89 (void)printf("%s ", etherproto_string(sllp
->sll_protocol
));
90 (void)printf("%d: ", length
);
94 * This is the top level routine of the printer. 'p' is the points
95 * to the ether header of the packet, 'h->tv' is the timestamp,
96 * 'h->length' is the length of the packet off the wire, and 'h->caplen'
97 * is the number of bytes actually captured.
100 sll_if_print(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*p
)
102 u_int caplen
= h
->caplen
;
103 u_int length
= h
->len
;
104 register const struct sll_header
*sllp
;
106 struct ether_header ehdr
;
108 u_short extracted_ethertype
;
113 if (caplen
< SLL_HDR_LEN
) {
115 * XXX - this "can't happen" because "pcap-linux.c" always
116 * adds this many bytes of header to every packet in a
117 * cooked socket capture.
123 sllp
= (const struct sll_header
*)p
;
126 * Fake up an Ethernet header for the benefit of printers that
127 * insist on "packetp" pointing to an Ethernet header.
129 pkttype
= ntohs(sllp
->sll_pkttype
);
131 /* The source address is in the packet header */
132 memcpy(ehdr
.ether_shost
, sllp
->sll_addr
, ETHER_ADDR_LEN
);
134 if (pkttype
!= LINUX_SLL_OUTGOING
) {
136 * We received this packet.
138 * We don't know the destination address, so
139 * we fake it - all 0's except that the
140 * bottommost bit of the bottommost octet
141 * is set for a unicast packet, all 0's except
142 * that the bottommost bit of the uppermost
143 * octet is set for a multicast packet, all
144 * 1's for a broadcast packet.
146 if (pkttype
== LINUX_SLL_BROADCAST
)
147 memset(ehdr
.ether_dhost
, 0xFF, ETHER_ADDR_LEN
);
149 memset(ehdr
.ether_dhost
, 0, ETHER_ADDR_LEN
);
150 if (pkttype
== LINUX_SLL_MULTICAST
)
151 ehdr
.ether_dhost
[0] = 1;
153 ehdr
.ether_dhost
[ETHER_ADDR_LEN
-1] = 1;
157 * We sent this packet; we don't know whether it's
158 * broadcast, multicast, or unicast, so just make
159 * the destination address all 0's.
161 memset(ehdr
.ether_dhost
, 0, ETHER_ADDR_LEN
);
165 sll_print(sllp
, length
);
168 * Some printers want to get back at the ethernet addresses,
169 * and/or check that they're not walking off the end of the packet.
170 * Rather than pass them all the way down, we set these globals.
172 snapend
= p
+ caplen
;
174 * Actually, the only printers that use packetp are print-arp.c
175 * and print-bootp.c, and they assume that packetp points to an
176 * Ethernet header. The right thing to do is to fix them to know
177 * which link type is in use when they excavate. XXX
179 packetp
= (u_char
*)&ehdr
;
181 length
-= SLL_HDR_LEN
;
182 caplen
-= SLL_HDR_LEN
;
185 ether_type
= ntohs(sllp
->sll_protocol
);
188 * Is it (gag) an 802.3 encapsulation, or some non-Ethernet
191 extracted_ethertype
= 0;
192 if (ether_type
<= ETHERMTU
) {
194 * Yes - what type is it?
196 switch (ether_type
) {
198 case LINUX_SLL_P_802_3
:
200 * Ethernet_802.3 IPX frame.
202 ipx_print(p
, length
);
205 case LINUX_SLL_P_802_2
:
208 * Try to print the LLC-layer header & higher layers.
210 if (llc_print(p
, length
, caplen
, ESRC(&ehdr
),
211 EDST(&ehdr
), &extracted_ethertype
) == 0)
212 goto unknown
; /* unknown LLC type */
217 /* ether_type not known, print raw packet */
219 sll_print(sllp
, length
+ SLL_HDR_LEN
);
220 if (extracted_ethertype
) {
222 etherproto_string(htons(extracted_ethertype
)));
224 if (!xflag
&& !qflag
)
225 default_print(p
, caplen
);
228 } else if (ether_encap_print(ether_type
, p
, length
, caplen
,
229 &extracted_ethertype
) == 0) {
230 /* ether_type not known, print raw packet */
232 sll_print(sllp
, length
+ SLL_HDR_LEN
);
233 if (!xflag
&& !qflag
)
234 default_print(p
, caplen
);
237 default_print(p
, caplen
);