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.4 2001-01-15 00:33:59 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"
50 const u_char
*packetp
;
51 const u_char
*snapend
;
54 sll_print(register const struct sll_header
*sllp
, u_int length
)
58 switch (ntohs(sllp
->sll_pkttype
)) {
64 case LINUX_SLL_BROADCAST
:
68 case LINUX_SLL_MULTICAST
:
72 case LINUX_SLL_OTHERHOST
:
76 case LINUX_SLL_OUTGOING
:
86 * XXX - check the link-layer address type value?
87 * For now, we just assume 6 means Ethernet.
88 * XXX - print others as strings of hex?
90 halen
= ntohs(sllp
->sll_halen
);
92 (void)printf("%s ", etheraddr_string(sllp
->sll_addr
));
95 (void)printf("%s ", etherproto_string(sllp
->sll_protocol
));
96 (void)printf("%d: ", length
);
100 * This is the top level routine of the printer. 'p' is the points
101 * to the ether header of the packet, 'h->tv' is the timestamp,
102 * 'h->length' is the length of the packet off the wire, and 'h->caplen'
103 * is the number of bytes actually captured.
106 sll_if_print(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*p
)
108 u_int caplen
= h
->caplen
;
109 u_int length
= h
->len
;
110 register const struct sll_header
*sllp
;
112 struct ether_header ehdr
;
114 u_short extracted_ethertype
;
118 if (caplen
< SLL_HDR_LEN
) {
120 * XXX - this "can't happen" because "pcap-linux.c" always
121 * adds this many bytes of header to every packet in a
122 * cooked socket capture.
128 sllp
= (const struct sll_header
*)p
;
131 * Fake up an Ethernet header for the benefit of printers that
132 * insist on "packetp" pointing to an Ethernet header.
134 pkttype
= ntohs(sllp
->sll_pkttype
);
136 /* The source address is in the packet header */
137 memcpy(ehdr
.ether_shost
, sllp
->sll_addr
, ETHER_ADDR_LEN
);
139 if (pkttype
!= LINUX_SLL_OUTGOING
) {
141 * We received this packet.
143 * We don't know the destination address, so
144 * we fake it - all 0's except that the
145 * bottommost bit of the bottommost octet
146 * is set for a unicast packet, all 0's except
147 * that the bottommost bit of the uppermost
148 * octet is set for a multicast packet, all
149 * 1's for a broadcast packet.
151 if (pkttype
== LINUX_SLL_BROADCAST
)
152 memset(ehdr
.ether_dhost
, 0xFF, ETHER_ADDR_LEN
);
154 memset(ehdr
.ether_dhost
, 0, ETHER_ADDR_LEN
);
155 if (pkttype
== LINUX_SLL_MULTICAST
)
156 ehdr
.ether_dhost
[0] = 1;
158 ehdr
.ether_dhost
[ETHER_ADDR_LEN
-1] = 1;
162 * We sent this packet; we don't know whether it's
163 * broadcast, multicast, or unicast, so just make
164 * the destination address all 0's.
166 memset(ehdr
.ether_dhost
, 0, ETHER_ADDR_LEN
);
170 sll_print(sllp
, length
);
173 * Some printers want to get back at the ethernet addresses,
174 * and/or check that they're not walking off the end of the packet.
175 * Rather than pass them all the way down, we set these globals.
177 snapend
= p
+ caplen
;
179 * Actually, the only printers that use packetp are print-arp.c
180 * and print-bootp.c, and they assume that packetp points to an
181 * Ethernet header. The right thing to do is to fix them to know
182 * which link type is in use when they excavate. XXX
184 packetp
= (u_char
*)&ehdr
;
186 length
-= SLL_HDR_LEN
;
187 caplen
-= SLL_HDR_LEN
;
190 ether_type
= ntohs(sllp
->sll_protocol
);
193 * Is it (gag) an 802.3 encapsulation, or some non-Ethernet
196 extracted_ethertype
= 0;
197 if (ether_type
<= ETHERMTU
) {
199 * Yes - what type is it?
201 switch (ether_type
) {
203 case LINUX_SLL_P_802_3
:
205 * Ethernet_802.3 IPX frame.
207 ipx_print(p
, length
);
210 case LINUX_SLL_P_802_2
:
213 * Try to print the LLC-layer header & higher layers.
215 if (llc_print(p
, length
, caplen
, ESRC(&ehdr
),
216 EDST(&ehdr
), &extracted_ethertype
) == 0)
217 goto unknown
; /* unknown LLC type */
222 /* ether_type not known, print raw packet */
224 sll_print(sllp
, length
+ SLL_HDR_LEN
);
225 if (extracted_ethertype
) {
227 etherproto_string(htons(extracted_ethertype
)));
229 if (!xflag
&& !qflag
)
230 default_print(p
, caplen
);
233 } else if (ether_encap_print(ether_type
, p
, length
, caplen
,
234 &extracted_ethertype
) == 0) {
235 /* ether_type not known, print raw packet */
237 sll_print(sllp
, length
+ SLL_HDR_LEN
);
238 if (!xflag
&& !qflag
)
239 default_print(p
, caplen
);
242 default_print(p
, caplen
);