]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
6d2010ae | 2 | * Copyright (c) 2000-2010 Apple Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
0a7de745 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
2d21ac55 A |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
0a7de745 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * Fundamental constants relating to ethernet. | |
30 | * | |
31 | */ | |
32 | ||
33 | #ifndef _NET_ETHERNET_H_ | |
34 | #define _NET_ETHERNET_H_ | |
9bccf70c | 35 | #include <sys/appleapiopts.h> |
0a7de745 | 36 | #include <sys/types.h> /* u_ types */ |
1c79356b A |
37 | |
38 | /* | |
39 | * The number of bytes in an ethernet (MAC) address. | |
40 | */ | |
0a7de745 | 41 | #define ETHER_ADDR_LEN 6 |
1c79356b A |
42 | |
43 | /* | |
44 | * The number of bytes in the type field. | |
45 | */ | |
0a7de745 | 46 | #define ETHER_TYPE_LEN 2 |
1c79356b A |
47 | |
48 | /* | |
49 | * The number of bytes in the trailing CRC field. | |
50 | */ | |
0a7de745 | 51 | #define ETHER_CRC_LEN 4 |
1c79356b A |
52 | |
53 | /* | |
54 | * The length of the combined header. | |
55 | */ | |
0a7de745 | 56 | #define ETHER_HDR_LEN (ETHER_ADDR_LEN*2+ETHER_TYPE_LEN) |
1c79356b A |
57 | |
58 | /* | |
59 | * The minimum packet length. | |
60 | */ | |
0a7de745 | 61 | #define ETHER_MIN_LEN 64 |
1c79356b A |
62 | |
63 | /* | |
64 | * The maximum packet length. | |
65 | */ | |
0a7de745 | 66 | #define ETHER_MAX_LEN 1518 |
1c79356b | 67 | |
6d2010ae A |
68 | /* |
69 | * Mbuf adjust factor to force 32-bit alignment of IP header. | |
70 | * Drivers should do m_adj(m, ETHER_ALIGN) when setting up a | |
71 | * receive so the upper layers get the IP header properly aligned | |
72 | * past the 14-byte Ethernet header. | |
73 | */ | |
74 | #define ETHER_ALIGN 2 /* driver adjust for IP hdr alignment */ | |
75 | ||
1c79356b A |
76 | /* |
77 | * A macro to validate a length with | |
78 | */ | |
0a7de745 | 79 | #define ETHER_IS_VALID_LEN(foo) \ |
1c79356b A |
80 | ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN) |
81 | ||
82 | /* | |
83 | * Structure of a 10Mb/s Ethernet header. | |
84 | */ | |
0a7de745 A |
85 | typedef struct ether_header { |
86 | u_char ether_dhost[ETHER_ADDR_LEN]; | |
87 | u_char ether_shost[ETHER_ADDR_LEN]; | |
88 | u_short ether_type; | |
d9a64523 | 89 | } ether_header_t; |
1c79356b A |
90 | |
91 | /* | |
92 | * Structure of a 48-bit Ethernet address. | |
93 | */ | |
0a7de745 | 94 | typedef struct ether_addr { |
1c79356b | 95 | u_char octet[ETHER_ADDR_LEN]; |
d9a64523 | 96 | } ether_addr_t; |
1c79356b A |
97 | |
98 | #define ether_addr_octet octet | |
99 | ||
0a7de745 A |
100 | #define ETHERTYPE_PUP 0x0200 /* PUP protocol */ |
101 | #define ETHERTYPE_IP 0x0800 /* IP protocol */ | |
102 | #define ETHERTYPE_ARP 0x0806 /* Addr. resolution protocol */ | |
103 | #define ETHERTYPE_REVARP 0x8035 /* reverse Addr. resolution protocol */ | |
104 | #define ETHERTYPE_VLAN 0x8100 /* IEEE 802.1Q VLAN tagging */ | |
105 | #define ETHERTYPE_IPV6 0x86dd /* IPv6 */ | |
106 | #define ETHERTYPE_PAE 0x888e /* EAPOL PAE/802.1x */ | |
107 | #define ETHERTYPE_RSN_PREAUTH 0x88c7 /* 802.11i / RSN Pre-Authentication */ | |
108 | #define ETHERTYPE_PTP 0x88f7 /* IEEE 1588 Precision Time Protocol */ | |
109 | #define ETHERTYPE_LOOPBACK 0x9000 /* used to test interfaces */ | |
1c79356b A |
110 | /* XXX - add more useful types here */ |
111 | ||
112 | /* | |
113 | * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have | |
114 | * (type-ETHERTYPE_TRAIL)*512 bytes of data followed | |
115 | * by an ETHER type (as given above) and then the (variable-length) header. | |
116 | */ | |
0a7de745 A |
117 | #define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */ |
118 | #define ETHERTYPE_NTRAILER 16 | |
1c79356b | 119 | |
0a7de745 A |
120 | #define ETHERMTU (ETHER_MAX_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN) |
121 | #define ETHERMIN (ETHER_MIN_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN) | |
1c79356b | 122 | |
91447636 A |
123 | #ifdef KERNEL_PRIVATE |
124 | /* | |
125 | * The following are used by ethernet interfaces. | |
126 | */ | |
127 | ||
0a7de745 | 128 | struct ether_addr *ether_aton(const char *); |
91447636 A |
129 | |
130 | #ifdef BSD_KERNEL_PRIVATE | |
0a7de745 | 131 | extern u_char etherbroadcastaddr[ETHER_ADDR_LEN]; |
6d2010ae | 132 | |
5ba3f43e A |
133 | #if defined (__arm__) |
134 | ||
135 | #include <string.h> | |
136 | ||
137 | static __inline__ int | |
138 | _ether_cmp(const void * a, const void * b) | |
139 | { | |
0a7de745 | 140 | return memcmp(a, b, ETHER_ADDR_LEN); |
5ba3f43e A |
141 | } |
142 | ||
143 | #else /* __arm__ */ | |
6d2010ae A |
144 | |
145 | static __inline__ int | |
146 | _ether_cmp(const void * a, const void * b) | |
147 | { | |
148 | const u_int16_t * a_s = (const u_int16_t *)a; | |
149 | const u_int16_t * b_s = (const u_int16_t *)b; | |
0a7de745 | 150 | |
6d2010ae | 151 | if (a_s[0] != b_s[0] |
0a7de745 A |
152 | || a_s[1] != b_s[1] |
153 | || a_s[2] != b_s[2]) { | |
154 | return 1; | |
6d2010ae | 155 | } |
0a7de745 | 156 | return 0; |
6d2010ae A |
157 | } |
158 | ||
5ba3f43e | 159 | #endif /* __arm__ */ |
6d2010ae | 160 | #endif /* BSD_KERNEL_PRIVATE */ |
b7266188 A |
161 | |
162 | #define ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */ | |
163 | ||
91447636 | 164 | #endif /* KERNEL_PRIVATE */ |
1c79356b | 165 | |
9bccf70c | 166 | #ifndef KERNEL |
1c79356b A |
167 | #include <sys/cdefs.h> |
168 | ||
169 | /* | |
170 | * Ethernet address conversion/parsing routines. | |
171 | */ | |
172 | __BEGIN_DECLS | |
173 | ||
0a7de745 A |
174 | int ether_hostton(const char *, struct ether_addr *); |
175 | int ether_line(const char *, struct ether_addr *, char *); | |
176 | char *ether_ntoa(const struct ether_addr *); | |
177 | struct ether_addr *ether_aton(const char *); | |
178 | int ether_ntohost(char *, const struct ether_addr *); | |
1c79356b A |
179 | __END_DECLS |
180 | #endif /* !KERNEL */ | |
181 | ||
182 | #endif /* !_NET_ETHERNET_H_ */ |