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
[] _U_
=
23 "@(#) $Header: /tcpdump/master/tcpdump/print-sll.c,v 1.12.2.2 2003-11-16 08:51:44 guy 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' points to the
91 * Linux "cooked capture" header of the packet, 'h->ts' 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(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 u_short extracted_ethertype
;
104 if (caplen
< SLL_HDR_LEN
) {
106 * XXX - this "can't happen" because "pcap-linux.c" always
107 * adds this many bytes of header to every packet in a
108 * cooked socket capture.
114 sllp
= (const struct sll_header
*)p
;
117 sll_print(sllp
, length
);
120 * Go past the cooked-mode header.
122 length
-= SLL_HDR_LEN
;
123 caplen
-= SLL_HDR_LEN
;
126 ether_type
= ntohs(sllp
->sll_protocol
);
129 * Is it (gag) an 802.3 encapsulation, or some non-Ethernet
132 extracted_ethertype
= 0;
133 if (ether_type
<= ETHERMTU
) {
135 * Yes - what type is it?
137 switch (ether_type
) {
139 case LINUX_SLL_P_802_3
:
141 * Ethernet_802.3 IPX frame.
143 ipx_print(p
, length
);
146 case LINUX_SLL_P_802_2
:
149 * Try to print the LLC-layer header & higher layers.
151 if (llc_print(p
, length
, caplen
, NULL
, NULL
,
152 &extracted_ethertype
) == 0)
153 goto unknown
; /* unknown LLC type */
158 /* ether_type not known, print raw packet */
160 sll_print(sllp
, length
+ SLL_HDR_LEN
);
161 if (extracted_ethertype
) {
163 etherproto_string(htons(extracted_ethertype
)));
165 if (!xflag
&& !qflag
)
166 default_print(p
, caplen
);
169 } else if (ether_encap_print(ether_type
, p
, length
, caplen
,
170 &extracted_ethertype
) == 0) {
171 /* ether_type not known, print raw packet */
173 sll_print(sllp
, length
+ SLL_HDR_LEN
);
174 if (!xflag
&& !qflag
)
175 default_print(p
, caplen
);
178 return (SLL_HDR_LEN
);