1 /* 2 * Copyright (c) 1982, 1986 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 */ 12 13 #ifndef _netinet_if_ether_h 14 #define _netinet_if_ether_h 15 16 #pragma ident "%Z%%M% %I% %E% SMI" 17 18 /* 19 * The following include is for compatibility with SunOS 3.x and 20 * 4.3bsd. Newly written programs should include it separately. 21 */ 22 #include <net/if_arp.h> 23 24 /* 25 * Ethernet address - 6 octets 26 */ 27 struct ether_addr { 28 u_char ether_addr_octet[6]; 29 }; 30 31 /* 32 * Structure of a 10Mb/s Ethernet header. 33 */ 34 struct ether_header { 35 struct ether_addr ether_dhost; 36 struct ether_addr ether_shost; 37 u_short ether_type; 38 }; 39 40 #define ETHERTYPE_PUP 0x0200 /* PUP protocol */ 41 #define ETHERTYPE_IP 0x0800 /* IP protocol */ 42 #define ETHERTYPE_ARP 0x0806 /* Addr. resolution protocol */ 43 #define ETHERTYPE_REVARP 0x8035 /* Reverse ARP */ 44 45 /* 46 * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have 47 * (type-ETHERTYPE_TRAIL)*512 bytes of data followed 48 * by an ETHER type (as given above) and then the (variable-length) header. 49 */ 50 #define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */ 51 #define ETHERTYPE_NTRAILER 16 52 53 #define ETHERMTU 1500 54 #define ETHERMIN (60-14) 55 56 /* 57 * Ethernet Address Resolution Protocol. 58 * 59 * See RFC 826 for protocol description. Structure below is adapted 60 * to resolving internet addresses. Field names used correspond to 61 * RFC 826. 62 */ 63 struct ether_arp { 64 struct arphdr ea_hdr; /* fixed-size header */ 65 struct ether_addr arp_sha; /* sender hardware address */ 66 u_char arp_spa[4]; /* sender protocol address */ 67 struct ether_addr arp_tha; /* target hardware address */ 68 u_char arp_tpa[4]; /* target protocol address */ 69 }; 70 #define arp_hrd ea_hdr.ar_hrd 71 #define arp_pro ea_hdr.ar_pro 72 #define arp_hln ea_hdr.ar_hln 73 #define arp_pln ea_hdr.ar_pln 74 #define arp_op ea_hdr.ar_op 75 76 /* 77 * multicast address structure 78 * 79 * Keep a reference count for each multicast address so 80 * addresses loaded into chip are unique. 81 */ 82 struct mcaddr { 83 struct ether_addr mc_enaddr; /* multicast address */ 84 u_short mc_count; /* reference count */ 85 }; 86 #define MCADDRMAX 64 /* multicast addr table length */ 87 #define MCCOUNTMAX 4096 /* multicast addr max reference count */ 88 89 /* 90 * Structure shared between the ethernet driver modules and 91 * the address resolution code. For example, each ec_softc or il_softc 92 * begins with this structure. 93 * 94 * The structure contains a pointer to an array of multicast addresses. 95 * This pointer is NULL until the first successful SIOCADDMULTI ioctl 96 * is issued for the interface. 97 */ 98 struct arpcom { 99 struct ifnet ac_if; /* network-visible interface */ 100 struct ether_addr ac_enaddr; /* ethernet hardware address */ 101 struct in_addr ac_ipaddr; /* copy of ip address- XXX */ 102 struct mcaddr *ac_mcaddr; /* table of multicast addrs */ 103 u_short ac_nmcaddr; /* count of M/C addrs in use */ 104 struct in_addr ac_lastip; /* cache of last ARP lookup */ 105 struct ether_addr ac_lastarp; /* result of the last ARP */ 106 }; 107 108 /* 109 * Internet to ethernet address resolution table. 110 */ 111 struct arptab { 112 struct in_addr at_iaddr; /* internet address */ 113 union { 114 struct ether_addr atu_enaddr; /* ethernet address */ 115 long atu_tvsec; /* timestamp if incomplete */ 116 } at_union; 117 u_char at_timer; /* minutes since last reference */ 118 u_char at_flags; /* flags */ 119 struct mbuf *at_hold; /* last packet until resolved/timeout */ 120 }; 121 122 # define at_enaddr at_union.atu_enaddr 123 # define at_tvsec at_union.atu_tvsec 124 125 /* 126 * Compare two Ethernet addresses - assumes that the two given 127 * pointers can be referenced as shorts. On architectures 128 * where this is not the case, use bcmp instead. Note that like 129 * bcmp, we return zero if they are the SAME. 130 */ 131 #define ether_cmp(a,b) ( ((short *)b)[2] != ((short *)a)[2] || \ 132 ((short *)b)[1] != ((short *)a)[1] || ((short *)b)[0] != ((short *)a)[0] ) 133 134 /* 135 * Copy Ethernet addresses from a to b - assumes that the two given 136 * pointers can be referenced as shorts. On architectures 137 * where this is not the case, use bcopy instead. 138 */ 139 #define ether_copy(a,b) { ((short *)b)[0]=((short *)a)[0]; \ 140 ((short *)b)[1]=((short *)a)[1]; ((short *)b)[2]=((short *)a)[2]; } 141 142 /* 143 * Copy IP addresses from a to b - assumes that the two given 144 * pointers can be referenced as shorts. On architectures 145 * where this is not the case, use bcopy instead. 146 */ 147 #define ip_copy(a,b) { ((short *)b)[0]=((short *)a)[0]; \ 148 ((short *)b)[1]=((short *)a)[1]; } 149 150 #endif /* !_netinet_if_ether_h */ 151