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