]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/ethernet.h
a053dd85339c91a3fae8c6d0a3c5b17180bfa72a
[apple/xnu.git] / bsd / net / ethernet.h
1 /*
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * Fundamental constants relating to ethernet.
32 *
33 */
34
35 #ifndef _NET_ETHERNET_H_
36 #define _NET_ETHERNET_H_
37 #include <sys/appleapiopts.h>
38
39 /*
40 * The number of bytes in an ethernet (MAC) address.
41 */
42 #define ETHER_ADDR_LEN 6
43
44 /*
45 * The number of bytes in the type field.
46 */
47 #define ETHER_TYPE_LEN 2
48
49 /*
50 * The number of bytes in the trailing CRC field.
51 */
52 #define ETHER_CRC_LEN 4
53
54 /*
55 * The length of the combined header.
56 */
57 #define ETHER_HDR_LEN (ETHER_ADDR_LEN*2+ETHER_TYPE_LEN)
58
59 /*
60 * The minimum packet length.
61 */
62 #define ETHER_MIN_LEN 64
63
64 /*
65 * The maximum packet length.
66 */
67 #define ETHER_MAX_LEN 1518
68
69 /*
70 * A macro to validate a length with
71 */
72 #define ETHER_IS_VALID_LEN(foo) \
73 ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
74
75 /*
76 * Structure of a 10Mb/s Ethernet header.
77 */
78 struct ether_header {
79 u_char ether_dhost[ETHER_ADDR_LEN];
80 u_char ether_shost[ETHER_ADDR_LEN];
81 u_short ether_type;
82 };
83
84 /*
85 * Structure of a 48-bit Ethernet address.
86 */
87 struct ether_addr {
88 u_char octet[ETHER_ADDR_LEN];
89 };
90
91 #define ether_addr_octet octet
92
93 #define ETHERTYPE_PUP 0x0200 /* PUP protocol */
94 #define ETHERTYPE_IP 0x0800 /* IP protocol */
95 #define ETHERTYPE_ARP 0x0806 /* Addr. resolution protocol */
96 #define ETHERTYPE_REVARP 0x8035 /* reverse Addr. resolution protocol */
97 #define ETHERTYPE_VLAN 0x8100 /* IEEE 802.1Q VLAN tagging */
98 #define ETHERTYPE_IPV6 0x86dd /* IPv6 */
99 #define ETHERTYPE_LOOPBACK 0x9000 /* used to test interfaces */
100 /* XXX - add more useful types here */
101
102 /*
103 * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
104 * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
105 * by an ETHER type (as given above) and then the (variable-length) header.
106 */
107 #define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */
108 #define ETHERTYPE_NTRAILER 16
109
110 #define ETHERMTU (ETHER_MAX_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
111 #define ETHERMIN (ETHER_MIN_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
112
113 #ifdef KERNEL_PRIVATE
114 /*
115 * The following are used by ethernet interfaces.
116 */
117
118 struct ether_addr *ether_aton(const char *);
119
120 #ifdef BSD_KERNEL_PRIVATE
121 extern u_char etherbroadcastaddr[ETHER_ADDR_LEN];
122 #endif
123 #endif /* KERNEL_PRIVATE */
124
125 #ifndef KERNEL
126 #include <sys/cdefs.h>
127
128 /*
129 * Ethernet address conversion/parsing routines.
130 */
131 __BEGIN_DECLS
132
133 int ether_hostton(const char *, struct ether_addr *);
134 int ether_line(const char *, struct ether_addr *, char *);
135 char *ether_ntoa(const struct ether_addr *);
136 struct ether_addr *ether_aton(const char *);
137 int ether_ntohost(char *, const struct ether_addr *);
138 __END_DECLS
139 #endif /* !KERNEL */
140
141 #endif /* !_NET_ETHERNET_H_ */