xref: /minix3/sys/net/if_ether.h (revision f14fb602092e015ff630df58e17c2a9cd57d29b3)
1 /*	$NetBSD: if_ether.h,v 1.58 2010/05/19 20:41:59 christos Exp $	*/
2 
3 /*
4  * Copyright (c) 1982, 1986, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  *	@(#)if_ether.h	8.1 (Berkeley) 6/10/93
32  */
33 
34 #ifndef _NET_IF_ETHER_H_
35 #define _NET_IF_ETHER_H_
36 
37 /*
38  * Some basic Ethernet constants.
39  */
40 #define	ETHER_ADDR_LEN	6	/* length of an Ethernet address */
41 #define	ETHER_TYPE_LEN	2	/* length of the Ethernet type field */
42 #define	ETHER_CRC_LEN	4	/* length of the Ethernet CRC */
43 #define	ETHER_HDR_LEN	((ETHER_ADDR_LEN * 2) + ETHER_TYPE_LEN)
44 #define	ETHER_MIN_LEN	64	/* minimum frame length, including CRC */
45 #define	ETHER_MAX_LEN	1518	/* maximum frame length, including CRC */
46 #define	ETHER_MAX_LEN_JUMBO 9018 /* maximum jumbo frame len, including CRC */
47 
48 /*
49  * Some Ethernet extensions.
50  */
51 #define	ETHER_VLAN_ENCAP_LEN 4	/* length of 802.1Q VLAN encapsulation */
52 #define	ETHER_PPPOE_ENCAP_LEN 8	/* length of PPPoE encapsulation */
53 
54 /*
55  * Ethernet address - 6 octets
56  * this is only used by the ethers(3) functions.
57  */
58 struct ether_addr {
59 	uint8_t ether_addr_octet[ETHER_ADDR_LEN];
60 } __packed;
61 
62 /*
63  * Structure of a 10Mb/s Ethernet header.
64  */
65 struct ether_header {
66 	uint8_t  ether_dhost[ETHER_ADDR_LEN];
67 	uint8_t  ether_shost[ETHER_ADDR_LEN];
68 	uint16_t ether_type;
69 } __packed;
70 
71 #include <net/ethertypes.h>
72 
73 #define	ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */
74 #define	ETHER_IS_LOCAL(addr) (*(addr) & 0x02) /* is address local? */
75 
76 #define	ETHERMTU_JUMBO	(ETHER_MAX_LEN_JUMBO - ETHER_HDR_LEN - ETHER_CRC_LEN)
77 #define	ETHERMTU	(ETHER_MAX_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
78 #define	ETHERMIN	(ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
79 
80 /*
81  * Compute the maximum frame size based on ethertype (i.e. possible
82  * encapsulation) and whether or not an FCS is present.
83  */
84 #define	ETHER_MAX_FRAME(ifp, etype, hasfcs)				\
85 	((ifp)->if_mtu + ETHER_HDR_LEN +				\
86 	 ((hasfcs) ? ETHER_CRC_LEN : 0) +				\
87 	 (((etype) == ETHERTYPE_VLAN) ? ETHER_VLAN_ENCAP_LEN : 0) +	\
88 	 (((etype) == ETHERTYPE_PPPOE) ? ETHER_PPPOE_ENCAP_LEN : 0))
89 
90 /*
91  * Ethernet CRC32 polynomials (big- and little-endian verions).
92  */
93 #define	ETHER_CRC_POLY_LE	0xedb88320
94 #define	ETHER_CRC_POLY_BE	0x04c11db6
95 
96 /*
97  * Prototype ethers(3) functions.
98  */
99 #include <sys/cdefs.h>
100 __BEGIN_DECLS
101 char *	ether_ntoa(const struct ether_addr *);
102 struct ether_addr *
103 	ether_aton(const char *);
104 int	ether_ntohost(char *, const struct ether_addr *);
105 int	ether_hostton(const char *, struct ether_addr *);
106 int	ether_line(const char *, struct ether_addr *, char *);
107 __END_DECLS
108 
109 #endif /* !_NET_IF_ETHER_H_ */
110