xref: /minix3/external/bsd/libpcap/dist/pcap/sll.h (revision d56f51ea7d8b9045e5c8e2028422523d3f9a5840)
1*d56f51eaSDavid van Moolenbroek /*	$NetBSD: sll.h,v 1.2 2014/11/19 19:33:31 christos Exp $	*/
2*d56f51eaSDavid van Moolenbroek 
3*d56f51eaSDavid van Moolenbroek /*-
4*d56f51eaSDavid van Moolenbroek  * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
5*d56f51eaSDavid van Moolenbroek  *	The Regents of the University of California.  All rights reserved.
6*d56f51eaSDavid van Moolenbroek  *
7*d56f51eaSDavid van Moolenbroek  * This code is derived from the Stanford/CMU enet packet filter,
8*d56f51eaSDavid van Moolenbroek  * (net/enet.c) distributed as part of 4.3BSD, and code contributed
9*d56f51eaSDavid van Moolenbroek  * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
10*d56f51eaSDavid van Moolenbroek  * Berkeley Laboratory.
11*d56f51eaSDavid van Moolenbroek  *
12*d56f51eaSDavid van Moolenbroek  * Redistribution and use in source and binary forms, with or without
13*d56f51eaSDavid van Moolenbroek  * modification, are permitted provided that the following conditions
14*d56f51eaSDavid van Moolenbroek  * are met:
15*d56f51eaSDavid van Moolenbroek  * 1. Redistributions of source code must retain the above copyright
16*d56f51eaSDavid van Moolenbroek  *    notice, this list of conditions and the following disclaimer.
17*d56f51eaSDavid van Moolenbroek  * 2. Redistributions in binary form must reproduce the above copyright
18*d56f51eaSDavid van Moolenbroek  *    notice, this list of conditions and the following disclaimer in the
19*d56f51eaSDavid van Moolenbroek  *    documentation and/or other materials provided with the distribution.
20*d56f51eaSDavid van Moolenbroek  * 3. All advertising materials mentioning features or use of this software
21*d56f51eaSDavid van Moolenbroek  *    must display the following acknowledgement:
22*d56f51eaSDavid van Moolenbroek  *      This product includes software developed by the University of
23*d56f51eaSDavid van Moolenbroek  *      California, Berkeley and its contributors.
24*d56f51eaSDavid van Moolenbroek  * 4. Neither the name of the University nor the names of its contributors
25*d56f51eaSDavid van Moolenbroek  *    may be used to endorse or promote products derived from this software
26*d56f51eaSDavid van Moolenbroek  *    without specific prior written permission.
27*d56f51eaSDavid van Moolenbroek  *
28*d56f51eaSDavid van Moolenbroek  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29*d56f51eaSDavid van Moolenbroek  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30*d56f51eaSDavid van Moolenbroek  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31*d56f51eaSDavid van Moolenbroek  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32*d56f51eaSDavid van Moolenbroek  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33*d56f51eaSDavid van Moolenbroek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34*d56f51eaSDavid van Moolenbroek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35*d56f51eaSDavid van Moolenbroek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36*d56f51eaSDavid van Moolenbroek  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37*d56f51eaSDavid van Moolenbroek  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38*d56f51eaSDavid van Moolenbroek  * SUCH DAMAGE.
39*d56f51eaSDavid van Moolenbroek  */
40*d56f51eaSDavid van Moolenbroek 
41*d56f51eaSDavid van Moolenbroek /*
42*d56f51eaSDavid van Moolenbroek  * For captures on Linux cooked sockets, we construct a fake header
43*d56f51eaSDavid van Moolenbroek  * that includes:
44*d56f51eaSDavid van Moolenbroek  *
45*d56f51eaSDavid van Moolenbroek  *	a 2-byte "packet type" which is one of:
46*d56f51eaSDavid van Moolenbroek  *
47*d56f51eaSDavid van Moolenbroek  *		LINUX_SLL_HOST		packet was sent to us
48*d56f51eaSDavid van Moolenbroek  *		LINUX_SLL_BROADCAST	packet was broadcast
49*d56f51eaSDavid van Moolenbroek  *		LINUX_SLL_MULTICAST	packet was multicast
50*d56f51eaSDavid van Moolenbroek  *		LINUX_SLL_OTHERHOST	packet was sent to somebody else
51*d56f51eaSDavid van Moolenbroek  *		LINUX_SLL_OUTGOING	packet was sent *by* us;
52*d56f51eaSDavid van Moolenbroek  *
53*d56f51eaSDavid van Moolenbroek  *	a 2-byte Ethernet protocol field;
54*d56f51eaSDavid van Moolenbroek  *
55*d56f51eaSDavid van Moolenbroek  *	a 2-byte link-layer type;
56*d56f51eaSDavid van Moolenbroek  *
57*d56f51eaSDavid van Moolenbroek  *	a 2-byte link-layer address length;
58*d56f51eaSDavid van Moolenbroek  *
59*d56f51eaSDavid van Moolenbroek  *	an 8-byte source link-layer address, whose actual length is
60*d56f51eaSDavid van Moolenbroek  *	specified by the previous value.
61*d56f51eaSDavid van Moolenbroek  *
62*d56f51eaSDavid van Moolenbroek  * All fields except for the link-layer address are in network byte order.
63*d56f51eaSDavid van Moolenbroek  *
64*d56f51eaSDavid van Moolenbroek  * DO NOT change the layout of this structure, or change any of the
65*d56f51eaSDavid van Moolenbroek  * LINUX_SLL_ values below.  If you must change the link-layer header
66*d56f51eaSDavid van Moolenbroek  * for a "cooked" Linux capture, introduce a new DLT_ type (ask
67*d56f51eaSDavid van Moolenbroek  * "tcpdump-workers@lists.tcpdump.org" for one, so that you don't give it
68*d56f51eaSDavid van Moolenbroek  * a value that collides with a value already being used), and use the
69*d56f51eaSDavid van Moolenbroek  * new header in captures of that type, so that programs that can
70*d56f51eaSDavid van Moolenbroek  * handle DLT_LINUX_SLL captures will continue to handle them correctly
71*d56f51eaSDavid van Moolenbroek  * without any change, and so that capture files with different headers
72*d56f51eaSDavid van Moolenbroek  * can be told apart and programs that read them can dissect the
73*d56f51eaSDavid van Moolenbroek  * packets in them.
74*d56f51eaSDavid van Moolenbroek  */
75*d56f51eaSDavid van Moolenbroek 
76*d56f51eaSDavid van Moolenbroek #ifndef lib_pcap_sll_h
77*d56f51eaSDavid van Moolenbroek #define lib_pcap_sll_h
78*d56f51eaSDavid van Moolenbroek 
79*d56f51eaSDavid van Moolenbroek /*
80*d56f51eaSDavid van Moolenbroek  * A DLT_LINUX_SLL fake link-layer header.
81*d56f51eaSDavid van Moolenbroek  */
82*d56f51eaSDavid van Moolenbroek #define SLL_HDR_LEN	16		/* total header length */
83*d56f51eaSDavid van Moolenbroek #define SLL_ADDRLEN	8		/* length of address field */
84*d56f51eaSDavid van Moolenbroek 
85*d56f51eaSDavid van Moolenbroek struct sll_header {
86*d56f51eaSDavid van Moolenbroek 	u_int16_t sll_pkttype;		/* packet type */
87*d56f51eaSDavid van Moolenbroek 	u_int16_t sll_hatype;		/* link-layer address type */
88*d56f51eaSDavid van Moolenbroek 	u_int16_t sll_halen;		/* link-layer address length */
89*d56f51eaSDavid van Moolenbroek 	u_int8_t sll_addr[SLL_ADDRLEN];	/* link-layer address */
90*d56f51eaSDavid van Moolenbroek 	u_int16_t sll_protocol;		/* protocol */
91*d56f51eaSDavid van Moolenbroek };
92*d56f51eaSDavid van Moolenbroek 
93*d56f51eaSDavid van Moolenbroek /*
94*d56f51eaSDavid van Moolenbroek  * The LINUX_SLL_ values for "sll_pkttype"; these correspond to the
95*d56f51eaSDavid van Moolenbroek  * PACKET_ values on Linux, but are defined here so that they're
96*d56f51eaSDavid van Moolenbroek  * available even on systems other than Linux, and so that they
97*d56f51eaSDavid van Moolenbroek  * don't change even if the PACKET_ values change.
98*d56f51eaSDavid van Moolenbroek  */
99*d56f51eaSDavid van Moolenbroek #define LINUX_SLL_HOST		0
100*d56f51eaSDavid van Moolenbroek #define LINUX_SLL_BROADCAST	1
101*d56f51eaSDavid van Moolenbroek #define LINUX_SLL_MULTICAST	2
102*d56f51eaSDavid van Moolenbroek #define LINUX_SLL_OTHERHOST	3
103*d56f51eaSDavid van Moolenbroek #define LINUX_SLL_OUTGOING	4
104*d56f51eaSDavid van Moolenbroek 
105*d56f51eaSDavid van Moolenbroek /*
106*d56f51eaSDavid van Moolenbroek  * The LINUX_SLL_ values for "sll_protocol"; these correspond to the
107*d56f51eaSDavid van Moolenbroek  * ETH_P_ values on Linux, but are defined here so that they're
108*d56f51eaSDavid van Moolenbroek  * available even on systems other than Linux.  We assume, for now,
109*d56f51eaSDavid van Moolenbroek  * that the ETH_P_ values won't change in Linux; if they do, then:
110*d56f51eaSDavid van Moolenbroek  *
111*d56f51eaSDavid van Moolenbroek  *	if we don't translate them in "pcap-linux.c", capture files
112*d56f51eaSDavid van Moolenbroek  *	won't necessarily be readable if captured on a system that
113*d56f51eaSDavid van Moolenbroek  *	defines ETH_P_ values that don't match these values;
114*d56f51eaSDavid van Moolenbroek  *
115*d56f51eaSDavid van Moolenbroek  *	if we do translate them in "pcap-linux.c", that makes life
116*d56f51eaSDavid van Moolenbroek  *	unpleasant for the BPF code generator, as the values you test
117*d56f51eaSDavid van Moolenbroek  *	for in the kernel aren't the values that you test for when
118*d56f51eaSDavid van Moolenbroek  *	reading a capture file, so the fixup code run on BPF programs
119*d56f51eaSDavid van Moolenbroek  *	handed to the kernel ends up having to do more work.
120*d56f51eaSDavid van Moolenbroek  *
121*d56f51eaSDavid van Moolenbroek  * Add other values here as necessary, for handling packet types that
122*d56f51eaSDavid van Moolenbroek  * might show up on non-Ethernet, non-802.x networks.  (Not all the ones
123*d56f51eaSDavid van Moolenbroek  * in the Linux "if_ether.h" will, I suspect, actually show up in
124*d56f51eaSDavid van Moolenbroek  * captures.)
125*d56f51eaSDavid van Moolenbroek  */
126*d56f51eaSDavid van Moolenbroek #define LINUX_SLL_P_802_3	0x0001	/* Novell 802.3 frames without 802.2 LLC header */
127*d56f51eaSDavid van Moolenbroek #define LINUX_SLL_P_802_2	0x0004	/* 802.2 frames (not D/I/X Ethernet) */
128*d56f51eaSDavid van Moolenbroek 
129*d56f51eaSDavid van Moolenbroek #endif
130