Watt-32 tcp/ip  2.2 dev-rel.10
if_ether.h
Go to the documentation of this file.
1 
5 /* Modified for emx by hv 1994
6  *
7  * Copyright (c) 1982, 1986 Regents of the University of California.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  * must display the following acknowledgement:
20  * This product includes software developed by the University of
21  * California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  * may be used to endorse or promote products derived from this software
24  * without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  * from: @(#)if_ether.h 7.5 (Berkeley) 6/28/90
39  * $Id: if_ether.h,v 1.8 1994/02/02 05:58:54 hpeyerl Exp $
40  */
41 
42 #ifndef __NETINET_IF_ETHER_H
43 #define __NETINET_IF_ETHER_H
44 
45 #ifndef __SYS_MBUF_H
46 #include <sys/mbuf.h>
47 #endif
48 
49 #ifndef __NET_IF_H
50 #include <net/if.h>
51 #endif
52 
53 #ifndef __NET_IF_ARP_H
54 #include <net/if_arp.h>
55 #endif
56 
57 #include <sys/pack_on.h>
58 
59 /*
60  * Ethernet address - 6 octets
61  * this is only used by the ethers(3) functions.
62  */
63 struct ether_addr {
64  u_char ether_addr_octet[6];
65  };
66 
67 /*
68  * Structure of a 10Mb/s Ethernet header.
69  */
70 struct ether_header {
71  u_char ether_dhost[6];
72  u_char ether_shost[6];
73  u_short ether_type;
74  };
75 
76 #define ETHERTYPE_PUP 0x0200 /* PUP protocol */
77 /* the IBM header corrects the following to 0x608 for OS/2 but I believe
78  * this is just a dirty hack
79  */
80 #define ETHERTYPE_ARP 0x0806 /* address resolution protocol */
81 #define ETHERTYPE_IP 0x0800 /* IP protocol */
82 #define ETHERTYPE_REVARP 0x8035 /* reverse addr resolution protocol */
83 
84 /*
85  * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
86  * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
87  * by an ETHER type (as given above) and then the (variable-length) header.
88  */
89 #define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */
90 #define ETHERTYPE_NTRAILER 16
91 
92 #define ETHERMTU 1500
93 #define ETHERMIN (60-14)
94 
95 /*
96  * Macro to map an IP multicast address to an Ethernet multicast address.
97  * The high-order 25 bits of the Ethernet address are statically assigned,
98  * and the low-order 23 bits are taken from the low end of the IP address.
99  */
100 #define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
101  /* struct in_addr *ipaddr; */ \
102  /* u_char enaddr[6]; */ \
103  { \
104  (enaddr)[0] = 0x01; \
105  (enaddr)[1] = 0x00; \
106  (enaddr)[2] = 0x5e; \
107  (enaddr)[3] = ((u_char *)ipaddr)[1] & 0x7f; \
108  (enaddr)[4] = ((u_char *)ipaddr)[2]; \
109  (enaddr)[5] = ((u_char *)ipaddr)[3]; \
110  }
111 
112 
113 /*
114  * Ethernet Address Resolution Protocol.
115  *
116  * See RFC 826 for protocol description. Structure below is adapted
117  * to resolving internet addresses. Field names used correspond to
118  * RFC 826.
119  */
120 struct ether_arp {
121  struct arphdr ea_hdr; /* fixed-size header */
122  u_char arp_sha[6]; /* sender hardware address */
123  u_char arp_spa[4]; /* sender protocol address */
124  u_char arp_tha[6]; /* target hardware address */
125  u_char arp_tpa[4]; /* target protocol address */
126  };
127 #define arp_hrd ea_hdr.ar_hrd
128 #define arp_pro ea_hdr.ar_pro
129 #define arp_hln ea_hdr.ar_hln
130 #define arp_pln ea_hdr.ar_pln
131 #define arp_op ea_hdr.ar_op
132 
133 
134 /*
135  * Structure shared between the ethernet driver modules and
136  * the address resolution code. For example, each ec_softc or il_softc
137  * begins with this structure.
138  */
139 struct arpcom {
140  struct ifnet ac_if; /* network-visible interface */
141  u_char ac_enaddr[6]; /* ethernet hardware address */
142  struct in_addr ac_ipaddr; /* copy of ip address- XXX */
143  struct ether_multi *ac_multiaddrs; /* list of ether multicast addrs */
144  int ac_multicnt; /* length of ac_multiaddrs list */
145 };
146 
147 /*
148  * Internet to ethernet address resolution table.
149  */
150 
151 struct arptab {
152  struct in_addr at_iaddr; /* internet address */
153  u_char at_enaddr[6]; /* ethernet address */
154  u_char at_timer; /* minutes since last reference */
155  u_char at_flags; /* flags */
156  struct mbuf *at_hold; /* last packet until resolved/timeout */
157 /* only os2 */
158  u_short at_rcf;
159  u_short at_rseg[8];
160  u_long at_millisec;
161  int at_interface;
162 };
163 
164 
165 extern u_char etherbroadcastaddr[6];
166 extern u_char ether_ipmulticast_min[6];
167 extern u_char ether_ipmulticast_max[6];
168 
169 /*
170  * Ethernet multicast address structure. There is one of these for each
171  * multicast address or range of multicast addresses that we are supposed
172  * to listen to on a particular interface. They are kept in a linked list,
173  * rooted in the interface's arpcom structure. (This really has nothing to
174  * do with ARP, or with the Internet address family, but this appears to be
175  * the minimally-disrupting place to put it.)
176  */
177 struct ether_multi {
178  u_char enm_addrlo[6]; /* low or only address of range */
179  u_char enm_addrhi[6]; /* high or only address of range */
180  struct arpcom *enm_ac; /* back pointer to arpcom */
181  u_int enm_refcount; /* no. claims to this addr/range */
182  struct ether_multi *enm_next; /* ptr to next ether_multi */
183  };
184 
185 /*
186  * Structure used by macros below to remember position when stepping through
187  * all of the ether_multi records.
188  */
190  struct ether_multi *e_enm;
191  };
192 
193 #include <sys/pack_off.h>
194 
195 /*
196  * Macro for looking up the ether_multi record for a given range of Ethernet
197  * multicast addresses connected to a given arpcom structure. If no matching
198  * record is found, "enm" returns NULL.
199  */
200 #define ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm) \
201  /* u_char addrlo[6]; */ \
202  /* u_char addrhi[6]; */ \
203  /* struct arpcom *ac; */ \
204  /* struct ether_multi *enm; */ \
205 { \
206  for ((enm) = (ac)->ac_multiaddrs; \
207  (enm) != NULL && \
208  (bcmp((enm)->enm_addrlo, (addrlo), 6) != 0 || \
209  bcmp((enm)->enm_addrhi, (addrhi), 6) != 0); \
210  (enm) = (enm)->enm_next); \
211 }
212 
213 /*
214  * Macro to step through all of the ether_multi records, one at a time.
215  * The current position is remembered in "step", which the caller must
216  * provide. ETHER_FIRST_MULTI(), below, must be called to initialize "step"
217  * and get the first record. Both macros return a NULL "enm" when there
218  * are no remaining records.
219  */
220 #define ETHER_NEXT_MULTI(step, enm) \
221  /* struct ether_multistep step; */ \
222  /* struct ether_multi *enm; */ \
223 { \
224  if (((enm) = (step).e_enm) != NULL) \
225  (step).e_enm = (enm)->enm_next; \
226 }
227 
228 #define ETHER_FIRST_MULTI(step, ac, enm) \
229  /* struct ether_multistep step; */ \
230  /* struct arpcom *ac; */ \
231  /* struct ether_multi *enm; */ \
232 { \
233  (step).e_enm = (ac)->ac_multiaddrs; \
234  ETHER_NEXT_MULTI((step), (enm)); \
235 }
236 
237 #endif
Definition: if_arp.h:57
Definition: in.h:146
Definition: if.h:130
Definition: mbuf.h:6