4 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 #include <sys/cdefs.h>
26 static const char rcsid
[] _U_
=
27 "@(#) Header: /tcpdump/master/tcpdump/print-sll.c,v 1.16.2.3 2005/11/13 12:13:00 guy Exp (LBL)";
29 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
37 #include <tcpdump-stdinc.h>
43 #include "interface.h"
44 #include "addrtoname.h"
45 #include "ethertype.h"
51 const struct tok sll_pkttype_values
[] = {
52 { LINUX_SLL_HOST
, "In" },
53 { LINUX_SLL_BROADCAST
, "B" },
54 { LINUX_SLL_MULTICAST
, "M" },
55 { LINUX_SLL_OTHERHOST
, "P" },
56 { LINUX_SLL_OUTGOING
, "Out" },
61 sll_print(register const struct sll_header
*sllp
, u_int length
)
65 printf("%3s ",tok2str(sll_pkttype_values
,"?",EXTRACT_16BITS(&sllp
->sll_pkttype
)));
68 * XXX - check the link-layer address type value?
69 * For now, we just assume 6 means Ethernet.
70 * XXX - print others as strings of hex?
72 if (EXTRACT_16BITS(&sllp
->sll_halen
) == 6)
73 (void)printf("%s ", etheraddr_string(sllp
->sll_addr
));
76 ether_type
= EXTRACT_16BITS(&sllp
->sll_protocol
);
78 if (ether_type
<= ETHERMTU
) {
80 * Not an Ethernet type; what type is it?
84 case LINUX_SLL_P_802_3
:
86 * Ethernet_802.3 IPX frame.
88 (void)printf("802.3");
91 case LINUX_SLL_P_802_2
:
95 (void)printf("802.3");
102 (void)printf("ethertype Unknown (0x%04x)",
107 (void)printf("ethertype %s (0x%04x)",
108 tok2str(ethertype_values
, "Unknown", ether_type
),
111 (void)printf(", length %u: ", length
);
116 * This is the top level routine of the printer. 'p' points to the
117 * Linux "cooked capture" header of the packet, 'h->ts' is the timestamp,
118 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
119 * is the number of bytes actually captured.
122 sll_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
124 u_int caplen
= h
->caplen
;
125 u_int length
= h
->len
;
126 register const struct sll_header
*sllp
;
128 u_short extracted_ethertype
;
130 if (caplen
< SLL_HDR_LEN
) {
132 * XXX - this "can't happen" because "pcap-linux.c" always
133 * adds this many bytes of header to every packet in a
134 * cooked socket capture.
140 sllp
= (const struct sll_header
*)p
;
143 sll_print(sllp
, length
);
146 * Go past the cooked-mode header.
148 length
-= SLL_HDR_LEN
;
149 caplen
-= SLL_HDR_LEN
;
152 ether_type
= ntohs(sllp
->sll_protocol
);
155 * Is it (gag) an 802.3 encapsulation, or some non-Ethernet
158 if (ether_type
<= ETHERMTU
) {
160 * Yes - what type is it?
162 switch (ether_type
) {
164 case LINUX_SLL_P_802_3
:
166 * Ethernet_802.3 IPX frame.
168 ipx_print(p
, length
);
171 case LINUX_SLL_P_802_2
:
174 * Try to print the LLC-layer header & higher layers.
176 if (llc_print(p
, length
, caplen
, NULL
, NULL
,
177 &extracted_ethertype
) == 0)
178 goto unknown
; /* unknown LLC type */
182 extracted_ethertype
= 0;
186 /* ether_type not known, print raw packet */
188 sll_print(sllp
, length
+ SLL_HDR_LEN
);
189 if (extracted_ethertype
) {
191 etherproto_string(htons(extracted_ethertype
)));
193 if (!suppress_default_print
)
194 default_print(p
, caplen
);
197 } else if (ether_encap_print(ether_type
, p
, length
, caplen
,
198 &extracted_ethertype
) == 0) {
199 /* ether_type not known, print raw packet */
201 sll_print(sllp
, length
+ SLL_HDR_LEN
);
202 if (!suppress_default_print
)
203 default_print(p
, caplen
);
206 return (SLL_HDR_LEN
);