2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1982, 1986, 1993
27 * The Regents of the University of California. All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in the
36 * documentation and/or other materials provided with the distribution.
37 * 3. All advertising materials mentioning features or use of this software
38 * must display the following acknowledgement:
39 * This product includes software developed by the University of
40 * California, Berkeley and its contributors.
41 * 4. Neither the name of the University nor the names of its contributors
42 * may be used to endorse or promote products derived from this software
43 * without specific prior written permission.
45 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * @(#)if_ether.h 8.3 (Berkeley) 5/2/95
58 * $FreeBSD: src/sys/netinet/if_ether.h,v 1.24 1999/12/29 04:40:58 peter Exp $
61 #ifndef _NETINET_IF_ETHER_H_
62 #define _NETINET_IF_ETHER_H_
63 #include <sys/appleapiopts.h>
65 #include <net/ethernet.h>
67 #include <netinet/in.h>
68 #include <net/if_arp.h>
69 #define ea_byte ether_addr_octet
72 #ifdef __APPLE_API_UNSTABLE
74 * Macro for looking up the ether_multi record for a given range of Ethernet
75 * multicast addresses connected to a given arpcom structure. If no matching
76 * record is found, "enm" returns NULL.
78 #define ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm) \
79 /* u_char addrlo[6]; */ \
80 /* u_char addrhi[6]; */ \
81 /* struct arpcom *ac; */ \
82 /* struct ether_multi *enm; */ \
84 for ((enm) = (ac)->ac_multiaddrs; \
86 (bcmp((enm)->enm_addrlo, (addrlo), 6) != 0 || \
87 bcmp((enm)->enm_addrhi, (addrhi), 6) != 0); \
88 (enm) = (enm)->enm_next); \
92 * Macro to step through all of the ether_multi records, one at a time.
93 * The current position is remembered in "step", which the caller must
94 * provide. ETHER_FIRST_MULTI(), below, must be called to initialize "step"
95 * and get the first record. Both macros return a NULL "enm" when there
96 * are no remaining records.
98 #define ETHER_NEXT_MULTI(step, enm) \
99 /* struct ether_multistep step; */ \
100 /* struct ether_multi *enm; */ \
102 if (((enm) = (step).e_enm) != NULL) \
103 (step).e_enm = (enm)->enm_next; \
106 #define ETHER_FIRST_MULTI(step, ac, enm) \
107 /* struct ether_multistep step; */ \
108 /* struct arpcom *ac; */ \
109 /* struct ether_multi *enm; */ \
111 (step).e_enm = (ac)->ac_multiaddrs; \
112 ETHER_NEXT_MULTI((step), (enm)); \
114 #endif /* __APPLE_API_UNSTABLE */
115 #endif /* __APPLE__ */
118 * Macro to map an IP multicast address to an Ethernet multicast address.
119 * The high-order 25 bits of the Ethernet address are statically assigned,
120 * and the low-order 23 bits are taken from the low end of the IP address.
122 #define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
123 /* struct in_addr *ipaddr; */ \
124 /* u_char enaddr[ETHER_ADDR_LEN]; */ \
126 (enaddr)[0] = 0x01; \
127 (enaddr)[1] = 0x00; \
128 (enaddr)[2] = 0x5e; \
129 (enaddr)[3] = ((u_char *)ipaddr)[1] & 0x7f; \
130 (enaddr)[4] = ((u_char *)ipaddr)[2]; \
131 (enaddr)[5] = ((u_char *)ipaddr)[3]; \
134 * Macro to map an IP6 multicast address to an Ethernet multicast address.
135 * The high-order 16 bits of the Ethernet address are statically assigned,
136 * and the low-order 32 bits are taken from the low end of the IP6 address.
138 #define ETHER_MAP_IPV6_MULTICAST(ip6addr, enaddr) \
139 /* struct in6_addr *ip6addr; */ \
140 /* u_char enaddr[ETHER_ADDR_LEN]; */ \
142 (enaddr)[0] = 0x33; \
143 (enaddr)[1] = 0x33; \
144 (enaddr)[2] = ((u_char *)ip6addr)[12]; \
145 (enaddr)[3] = ((u_char *)ip6addr)[13]; \
146 (enaddr)[4] = ((u_char *)ip6addr)[14]; \
147 (enaddr)[5] = ((u_char *)ip6addr)[15]; \
151 * Ethernet Address Resolution Protocol.
153 * See RFC 826 for protocol description. Structure below is adapted
154 * to resolving internet addresses. Field names used correspond to
158 struct arphdr ea_hdr
; /* fixed-size header */
159 u_char arp_sha
[ETHER_ADDR_LEN
]; /* sender hardware address */
160 u_char arp_spa
[4]; /* sender protocol address */
161 u_char arp_tha
[ETHER_ADDR_LEN
]; /* target hardware address */
162 u_char arp_tpa
[4]; /* target protocol address */
164 #define arp_hrd ea_hdr.ar_hrd
165 #define arp_pro ea_hdr.ar_pro
166 #define arp_hln ea_hdr.ar_hln
167 #define arp_pln ea_hdr.ar_pln
168 #define arp_op ea_hdr.ar_op
170 struct sockaddr_inarp
{
174 struct in_addr sin_addr
;
175 struct in_addr sin_srcaddr
;
181 * IP and ethernet specific routing flags
183 #define RTF_USETRAILERS RTF_PROTO1 /* use trailers */
184 #define RTF_ANNOUNCE RTF_PROTO2 /* announce new arp entry */
187 #ifdef __APPLE_API_PRIVATE
188 extern u_char ether_ipmulticast_min
[ETHER_ADDR_LEN
];
189 extern u_char ether_ipmulticast_max
[ETHER_ADDR_LEN
];
190 extern struct ifqueue arpintrq
;
192 int arpresolve
__P((struct arpcom
*, struct rtentry
*, struct mbuf
*,
193 struct sockaddr
*, u_char
*, struct rtentry
*));
194 #endif /* __APPLE_API_PRIVATE */
195 #ifdef __APPLE_API_UNSTABLE
196 void arp_ifinit
__P((struct arpcom
*, struct ifaddr
*));
197 #endif /* __APPLE_API_UNSTABLE */