]> git.saurik.com Git - apple/xnu.git/blame - bsd/netinet/if_ether.h
xnu-517.tar.gz
[apple/xnu.git] / bsd / netinet / if_ether.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
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
13 * file.
14 *
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
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
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.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * Copyright (c) 1982, 1986, 1993
27 * The Regents of the University of California. All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
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.
44 *
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
55 * SUCH DAMAGE.
56 *
57 * @(#)if_ether.h 8.3 (Berkeley) 5/2/95
9bccf70c 58 * $FreeBSD: src/sys/netinet/if_ether.h,v 1.24 1999/12/29 04:40:58 peter Exp $
1c79356b
A
59 */
60
61#ifndef _NETINET_IF_ETHER_H_
62#define _NETINET_IF_ETHER_H_
9bccf70c 63#include <sys/appleapiopts.h>
1c79356b
A
64
65#include <net/ethernet.h>
66
67#include <netinet/in.h>
68#include <net/if_arp.h>
1c79356b
A
69#define ea_byte ether_addr_octet
70
9bccf70c
A
71#ifdef __APPLE__
72#ifdef __APPLE_API_UNSTABLE
1c79356b
A
73/*
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.
77 */
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; */ \
83{ \
84 for ((enm) = (ac)->ac_multiaddrs; \
85 (enm) != NULL && \
86 (bcmp((enm)->enm_addrlo, (addrlo), 6) != 0 || \
87 bcmp((enm)->enm_addrhi, (addrhi), 6) != 0); \
88 (enm) = (enm)->enm_next); \
89}
90
91/*
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.
97 */
98#define ETHER_NEXT_MULTI(step, enm) \
99 /* struct ether_multistep step; */ \
100 /* struct ether_multi *enm; */ \
101{ \
102 if (((enm) = (step).e_enm) != NULL) \
103 (step).e_enm = (enm)->enm_next; \
104}
105
106#define ETHER_FIRST_MULTI(step, ac, enm) \
107 /* struct ether_multistep step; */ \
108 /* struct arpcom *ac; */ \
109 /* struct ether_multi *enm; */ \
110{ \
111 (step).e_enm = (ac)->ac_multiaddrs; \
112 ETHER_NEXT_MULTI((step), (enm)); \
113}
9bccf70c
A
114#endif /* __APPLE_API_UNSTABLE */
115#endif /* __APPLE__ */
1c79356b 116
1c79356b
A
117/*
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.
121 */
122#define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
123 /* struct in_addr *ipaddr; */ \
124 /* u_char enaddr[ETHER_ADDR_LEN]; */ \
125{ \
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]; \
132}
133/*
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.
137 */
138#define ETHER_MAP_IPV6_MULTICAST(ip6addr, enaddr) \
9bccf70c
A
139/* struct in6_addr *ip6addr; */ \
140/* u_char enaddr[ETHER_ADDR_LEN]; */ \
1c79356b
A
141{ \
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]; \
148}
149
150/*
151 * Ethernet Address Resolution Protocol.
152 *
153 * See RFC 826 for protocol description. Structure below is adapted
154 * to resolving internet addresses. Field names used correspond to
155 * RFC 826.
156 */
157struct ether_arp {
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 */
163};
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
169
170struct sockaddr_inarp {
171 u_char sin_len;
172 u_char sin_family;
173 u_short sin_port;
174 struct in_addr sin_addr;
175 struct in_addr sin_srcaddr;
176 u_short sin_tos;
177 u_short sin_other;
178#define SIN_PROXY 1
179};
180/*
181 * IP and ethernet specific routing flags
182 */
183#define RTF_USETRAILERS RTF_PROTO1 /* use trailers */
184#define RTF_ANNOUNCE RTF_PROTO2 /* announce new arp entry */
185
186#ifdef KERNEL
9bccf70c 187#ifdef __APPLE_API_PRIVATE
1c79356b
A
188extern u_char ether_ipmulticast_min[ETHER_ADDR_LEN];
189extern u_char ether_ipmulticast_max[ETHER_ADDR_LEN];
190extern struct ifqueue arpintrq;
191
192int arpresolve __P((struct arpcom *, struct rtentry *, struct mbuf *,
193 struct sockaddr *, u_char *, struct rtentry *));
9bccf70c
A
194#endif /* __APPLE_API_PRIVATE */
195#ifdef __APPLE_API_UNSTABLE
1c79356b 196void arp_ifinit __P((struct arpcom *, struct ifaddr *));
9bccf70c 197#endif /* __APPLE_API_UNSTABLE */
1c79356b
A
198#endif
199
200#endif