rename project to visftp
[oftp] / libs / watt32 / netinet / if_ether.h
1 /*!\file inc/netinet/if_ether.h
2  * Ethernet definitions.
3  */
4
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 #include <sys/packon.h>
46
47 /*
48  * Ethernet address - 6 octets
49  * this is only used by the ethers(3) functions.
50  */
51 struct ether_addr {
52        u_char ether_addr_octet[6];
53      };
54
55 /*
56  * Structure of a 10Mb/s Ethernet header.
57  */
58 struct ether_header {
59        u_char  ether_dhost[6];
60        u_char  ether_shost[6];
61        u_short ether_type;
62      };
63
64 #define ETHERTYPE_PUP           0x0200  /* PUP protocol */
65 /* the IBM header corrects the following to 0x608 for OS/2 but I believe
66  * this is just a dirty hack 
67  */
68 #define ETHERTYPE_ARP           0x0806  /* address resolution protocol */
69 #define ETHERTYPE_IP            0x0800  /* IP protocol */
70 #define ETHERTYPE_REVARP        0x8035  /* reverse addr resolution protocol */
71
72 /*
73  * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
74  * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
75  * by an ETHER type (as given above) and then the (variable-length) header.
76  */
77 #define ETHERTYPE_TRAIL         0x1000          /* Trailer packet */
78 #define ETHERTYPE_NTRAILER      16
79
80 #define ETHERMTU                1500
81 #define ETHERMIN                (60-14)
82
83 /*
84  * Macro to map an IP multicast address to an Ethernet multicast address.
85  * The high-order 25 bits of the Ethernet address are statically assigned,
86  * and the low-order 23 bits are taken from the low end of the IP address.
87  */
88 #define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
89         /* struct in_addr *ipaddr; */ \
90         /* u_char enaddr[6];       */ \
91         { \
92           (enaddr)[0] = 0x01; \
93           (enaddr)[1] = 0x00; \
94           (enaddr)[2] = 0x5e; \
95           (enaddr)[3] = ((u_char *)ipaddr)[1] & 0x7f; \
96           (enaddr)[4] = ((u_char *)ipaddr)[2]; \
97           (enaddr)[5] = ((u_char *)ipaddr)[3]; \
98         }
99
100
101 /*
102  * Ethernet Address Resolution Protocol.
103  *
104  * See RFC 826 for protocol description.  Structure below is adapted
105  * to resolving internet addresses.  Field names used correspond to 
106  * RFC 826.
107  */
108 struct ether_arp {
109        struct  arphdr ea_hdr;  /* fixed-size header */
110        u_char  arp_sha[6];     /* sender hardware address */
111        u_char  arp_spa[4];     /* sender protocol address */
112        u_char  arp_tha[6];     /* target hardware address */
113        u_char  arp_tpa[4];     /* target protocol address */
114      };
115 #define arp_hrd ea_hdr.ar_hrd
116 #define arp_pro ea_hdr.ar_pro
117 #define arp_hln ea_hdr.ar_hln
118 #define arp_pln ea_hdr.ar_pln
119 #define arp_op  ea_hdr.ar_op
120
121
122 /*
123  * Structure shared between the ethernet driver modules and
124  * the address resolution code.  For example, each ec_softc or il_softc
125  * begins with this structure.
126  */
127 struct arpcom {
128        struct  ifnet ac_if;               /* network-visible interface */
129        u_char  ac_enaddr[6];              /* ethernet hardware address */
130        struct in_addr ac_ipaddr;          /* copy of ip address- XXX */
131        struct ether_multi *ac_multiaddrs; /* list of ether multicast addrs */
132        int ac_multicnt;                   /* length of ac_multiaddrs list */
133 };
134
135 /*
136  * Internet to ethernet address resolution table.
137  */
138
139 struct arptab {
140        struct  in_addr at_iaddr;       /* internet address */
141        u_char  at_enaddr[6];           /* ethernet address */
142        u_char  at_timer;               /* minutes since last reference */
143        u_char  at_flags;               /* flags */
144        struct  mbuf *at_hold;          /* last packet until resolved/timeout */
145 /* only os2 */
146        u_short at_rcf;
147        u_short at_rseg[8];
148        u_long at_millisec;
149        int at_interface;
150 };
151
152
153 extern u_char  etherbroadcastaddr[6];
154 extern u_char  ether_ipmulticast_min[6];
155 extern u_char  ether_ipmulticast_max[6];
156
157 /*
158  * Ethernet multicast address structure.  There is one of these for each
159  * multicast address or range of multicast addresses that we are supposed
160  * to listen to on a particular interface.  They are kept in a linked list,
161  * rooted in the interface's arpcom structure.  (This really has nothing to
162  * do with ARP, or with the Internet address family, but this appears to be
163  * the minimally-disrupting place to put it.)
164  */
165 struct ether_multi {
166        u_char  enm_addrlo[6];          /* low  or only address of range */
167        u_char  enm_addrhi[6];          /* high or only address of range */
168        struct  arpcom *enm_ac;         /* back pointer to arpcom */
169        u_int   enm_refcount;           /* no. claims to this addr/range */
170        struct  ether_multi *enm_next;  /* ptr to next ether_multi */
171      };
172
173 /*
174  * Structure used by macros below to remember position when stepping through
175  * all of the ether_multi records.
176  */
177 struct ether_multistep {
178        struct ether_multi  *e_enm;
179      };
180
181 #include <sys/packoff.h>
182
183 /*
184  * Macro for looking up the ether_multi record for a given range of Ethernet
185  * multicast addresses connected to a given arpcom structure.  If no matching
186  * record is found, "enm" returns NULL.
187  */
188 #define ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm) \
189         /* u_char addrlo[6]; */ \
190         /* u_char addrhi[6]; */ \
191         /* struct arpcom *ac; */ \
192         /* struct ether_multi *enm; */ \
193 { \
194         for ((enm) = (ac)->ac_multiaddrs; \
195             (enm) != NULL && \
196             (bcmp((enm)->enm_addrlo, (addrlo), 6) != 0 || \
197              bcmp((enm)->enm_addrhi, (addrhi), 6) != 0); \
198                 (enm) = (enm)->enm_next); \
199 }
200
201 /*
202  * Macro to step through all of the ether_multi records, one at a time.
203  * The current position is remembered in "step", which the caller must
204  * provide.  ETHER_FIRST_MULTI(), below, must be called to initialize "step"
205  * and get the first record.  Both macros return a NULL "enm" when there
206  * are no remaining records.
207  */
208 #define ETHER_NEXT_MULTI(step, enm) \
209         /* struct ether_multistep step; */  \
210         /* struct ether_multi *enm; */  \
211 { \
212         if (((enm) = (step).e_enm) != NULL) \
213                 (step).e_enm = (enm)->enm_next; \
214 }
215
216 #define ETHER_FIRST_MULTI(step, ac, enm) \
217         /* struct ether_multistep step; */ \
218         /* struct arpcom *ac; */ \
219         /* struct ether_multi *enm; */ \
220 { \
221         (step).e_enm = (ac)->ac_multiaddrs; \
222         ETHER_NEXT_MULTI((step), (enm)); \
223 }
224
225 #endif