blob: b1d2bce8727e2fcd164ccaecba1d7fc2a537c821 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/* $NetBSD: if_ether.h,v 1.43 2006/11/24 01:04:30 rpaulo 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
Elliott Hughes12f35412016-05-10 17:32:48 -070037#include <sys/cdefs.h>
Szymon Jakubczak41e533a2010-06-09 15:53:28 -040038#include <sys/types.h>
39
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080040/*
41 * Some basic Ethernet constants.
42 */
43#define ETHER_ADDR_LEN 6 /* length of an Ethernet address */
44#define ETHER_TYPE_LEN 2 /* length of the Ethernet type field */
45#define ETHER_CRC_LEN 4 /* length of the Ethernet CRC */
46#define ETHER_HDR_LEN ((ETHER_ADDR_LEN * 2) + ETHER_TYPE_LEN)
47#define ETHER_MIN_LEN 64 /* minimum frame length, including CRC */
48#define ETHER_MAX_LEN 1518 /* maximum frame length, including CRC */
49#define ETHER_MAX_LEN_JUMBO 9018 /* maximum jumbo frame len, including CRC */
50
51/*
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080052 * Ethernet address - 6 octets
53 * this is only used by the ethers(3) functions.
54 */
55struct ether_addr {
56 u_int8_t ether_addr_octet[ETHER_ADDR_LEN];
57} __attribute__((__packed__));
58
59/*
60 * Structure of a 10Mb/s Ethernet header.
61 */
62struct ether_header {
63 u_int8_t ether_dhost[ETHER_ADDR_LEN];
64 u_int8_t ether_shost[ETHER_ADDR_LEN];
65 u_int16_t ether_type;
66} __attribute__((__packed__));
67
68#include <net/ethertypes.h>
69
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080070#define ETHERMTU_JUMBO (ETHER_MAX_LEN_JUMBO - ETHER_HDR_LEN - ETHER_CRC_LEN)
71#define ETHERMTU (ETHER_MAX_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
72#define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
73
74/*
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080075 * Macro to map an IP multicast address to an Ethernet multicast address.
76 * The high-order 25 bits of the Ethernet address are statically assigned,
77 * and the low-order 23 bits are taken from the low end of the IP address.
78 */
79#define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
80 /* struct in_addr *ipaddr; */ \
81 /* u_int8_t enaddr[ETHER_ADDR_LEN]; */ \
82{ \
83 (enaddr)[0] = 0x01; \
84 (enaddr)[1] = 0x00; \
85 (enaddr)[2] = 0x5e; \
86 (enaddr)[3] = ((u_int8_t *)ipaddr)[1] & 0x7f; \
87 (enaddr)[4] = ((u_int8_t *)ipaddr)[2]; \
88 (enaddr)[5] = ((u_int8_t *)ipaddr)[3]; \
89}
90/*
91 * Macro to map an IP6 multicast address to an Ethernet multicast address.
92 * The high-order 16 bits of the Ethernet address are statically assigned,
93 * and the low-order 32 bits are taken from the low end of the IP6 address.
94 */
95#define ETHER_MAP_IPV6_MULTICAST(ip6addr, enaddr) \
96 /* struct in6_addr *ip6addr; */ \
97 /* u_int8_t enaddr[ETHER_ADDR_LEN]; */ \
98{ \
99 (enaddr)[0] = 0x33; \
100 (enaddr)[1] = 0x33; \
101 (enaddr)[2] = ((u_int8_t *)ip6addr)[12]; \
102 (enaddr)[3] = ((u_int8_t *)ip6addr)[13]; \
103 (enaddr)[4] = ((u_int8_t *)ip6addr)[14]; \
104 (enaddr)[5] = ((u_int8_t *)ip6addr)[15]; \
105}
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800106
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800107__BEGIN_DECLS
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800108
Elliott Hughes12f35412016-05-10 17:32:48 -0700109char* ether_ntoa(const struct ether_addr*) __INTRODUCED_IN(21);
110struct ether_addr* ether_aton(const char*) __INTRODUCED_IN(21);
111
112__END_DECLS
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800113
114#endif /* !_NET_IF_ETHER_H_ */