Annotation of kernel/bsd/netinet/if_ether.h, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.1 (the "License").  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License.
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: 
        !            25: /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
        !            26: /*
        !            27:  * Copyright (c) 1982, 1986, 1993
        !            28:  *     The Regents of the University of California.  All rights reserved.
        !            29:  *
        !            30:  * Redistribution and use in source and binary forms, with or without
        !            31:  * modification, are permitted provided that the following conditions
        !            32:  * are met:
        !            33:  * 1. Redistributions of source code must retain the above copyright
        !            34:  *    notice, this list of conditions and the following disclaimer.
        !            35:  * 2. Redistributions in binary form must reproduce the above copyright
        !            36:  *    notice, this list of conditions and the following disclaimer in the
        !            37:  *    documentation and/or other materials provided with the distribution.
        !            38:  * 3. All advertising materials mentioning features or use of this software
        !            39:  *    must display the following acknowledgement:
        !            40:  *     This product includes software developed by the University of
        !            41:  *     California, Berkeley and its contributors.
        !            42:  * 4. Neither the name of the University nor the names of its contributors
        !            43:  *    may be used to endorse or promote products derived from this software
        !            44:  *    without specific prior written permission.
        !            45:  *
        !            46:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            47:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            48:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            49:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            50:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            51:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            52:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            53:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            54:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            55:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            56:  * SUCH DAMAGE.
        !            57:  *
        !            58:  *     @(#)if_ether.h  8.1 (Berkeley) 6/10/93
        !            59:  */
        !            60: 
        !            61: #import <netinet/in.h>
        !            62: 
        !            63: /*
        !            64:  * Ethernet address - 6 octets
        !            65:  * this is only used by the ethers(3) functions.
        !            66:  */
        !            67: struct ether_addr {
        !            68:        u_char ether_addr_octet[6];
        !            69: };
        !            70: 
        !            71: #define ea_byte        ether_addr_octet
        !            72: 
        !            73: /*
        !            74:  * Structure of a 10Mb/s Ethernet header.
        !            75:  */
        !            76: struct ether_header {
        !            77:        u_char  ether_dhost[6];
        !            78:        u_char  ether_shost[6];
        !            79:        u_short ether_type;
        !            80: };
        !            81: 
        !            82: #define        ETHERTYPE_PUP           0x0200  /* PUP protocol */
        !            83: #define        ETHERTYPE_IP            0x0800  /* IP protocol */
        !            84: #define        ETHERTYPE_ARP           0x0806  /* address resolution protocol */
        !            85: #define        ETHERTYPE_REVARP        0x8035  /* reverse addr resolution protocol */
        !            86: 
        !            87: /*
        !            88:  * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
        !            89:  * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
        !            90:  * by an ETHER type (as given above) and then the (variable-length) header.
        !            91:  */
        !            92: #define        ETHERTYPE_TRAIL         0x1000          /* Trailer packet */
        !            93: #define        ETHERTYPE_NTRAILER      16
        !            94: 
        !            95: #define        ETHERMTU        1500
        !            96: #define        ETHERMIN        (60-14)
        !            97: 
        !            98: #ifdef _KERNEL
        !            99: /*
        !           100:  * Macro to map an IP multicast address to an Ethernet multicast address.
        !           101:  * The high-order 25 bits of the Ethernet address are statically assigned,
        !           102:  * and the low-order 23 bits are taken from the low end of the IP address.
        !           103:  */
        !           104: #define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
        !           105:        /* struct in_addr *ipaddr; */ \
        !           106:        /* u_char enaddr[6];       */ \
        !           107: { \
        !           108:        (enaddr)[0] = 0x01; \
        !           109:        (enaddr)[1] = 0x00; \
        !           110:        (enaddr)[2] = 0x5e; \
        !           111:        (enaddr)[3] = ((u_char *)ipaddr)[1] & 0x7f; \
        !           112:        (enaddr)[4] = ((u_char *)ipaddr)[2]; \
        !           113:        (enaddr)[5] = ((u_char *)ipaddr)[3]; \
        !           114: }
        !           115: #endif
        !           116: 
        !           117: /*
        !           118:  * Ethernet Address Resolution Protocol.
        !           119:  *
        !           120:  * See RFC 826 for protocol description.  Structure below is adapted
        !           121:  * to resolving internet addresses.  Field names used correspond to 
        !           122:  * RFC 826.
        !           123:  */
        !           124: struct ether_arp {
        !           125:        struct  arphdr ea_hdr;  /* fixed-size header */
        !           126:        u_char  arp_sha[6];     /* sender hardware address */
        !           127:        u_char  arp_spa[4];     /* sender protocol address */
        !           128:        u_char  arp_tha[6];     /* target hardware address */
        !           129:        u_char  arp_tpa[4];     /* target protocol address */
        !           130: };
        !           131: #define        arp_hrd ea_hdr.ar_hrd
        !           132: #define        arp_pro ea_hdr.ar_pro
        !           133: #define        arp_hln ea_hdr.ar_hln
        !           134: #define        arp_pln ea_hdr.ar_pln
        !           135: #define        arp_op  ea_hdr.ar_op
        !           136: 
        !           137: /*
        !           138:  * Structure shared between the ethernet driver modules and
        !           139:  * the address resolution code.  For example, each ec_softc or il_softc
        !           140:  * begins with this structure.
        !           141:  */
        !           142: struct arpcom {
        !           143:        struct  ifnet ac_if;            /* network-visible interface */
        !           144:        u_char  ac_enaddr[6];           /* ethernet hardware address */
        !           145:        struct  in_addr ac_ipaddr;      /* copy of ip address- XXX */
        !           146:        struct  ether_multi *ac_multiaddrs; /* list of ether multicast addrs */
        !           147:        int     ac_multicnt;            /* length of ac_multiaddrs list */
        !           148: };
        !           149: 
        !           150: struct llinfo_arp {
        !           151:        struct  llinfo_arp *la_next;
        !           152:        struct  llinfo_arp *la_prev;
        !           153:        struct  rtentry *la_rt;
        !           154:        struct  mbuf *la_hold;          /* last packet until resolved/timeout */
        !           155:        long    la_asked;               /* last time we QUERIED for this addr */
        !           156: #define la_timer la_rt->rt_rmx.rmx_expire /* deletion time in seconds */
        !           157: };
        !           158: 
        !           159: struct sockaddr_inarp {
        !           160:        u_char  sin_len;
        !           161:        u_char  sin_family;
        !           162:        u_short sin_port;
        !           163:        struct  in_addr sin_addr;
        !           164:        struct  in_addr sin_srcaddr;
        !           165:        u_short sin_tos;
        !           166:        u_short sin_other;
        !           167: #define SIN_PROXY 1
        !           168: };
        !           169: 
        !           170: /*
        !           171:  * IP and ethernet specific routing flags
        !           172:  */
        !           173: #define        RTF_USETRAILERS RTF_PROTO1      /* use trailers */
        !           174: #define        RTF_ANNOUNCE    RTF_PROTO2      /* announce new arp entry */
        !           175: 
        !           176: #ifdef _KERNEL
        !           177: extern u_char  etherbroadcastaddr[6];
        !           178: extern u_char  ether_ipmulticast_min[6];
        !           179: extern u_char  ether_ipmulticast_max[6];
        !           180: extern struct  ifqueue arpintrq;
        !           181: 
        !           182: extern struct  llinfo_arp llinfo_arp;          /* head of the llinfo queue */
        !           183: 
        !           184: void   arpwhohas __P((struct arpcom *, struct in_addr *));
        !           185: void   arpintr __P((void));
        !           186: int    arpresolve __P((struct arpcom *,
        !           187:           struct rtentry *, struct mbuf *, struct sockaddr *, u_char *));
        !           188: void   arp_rtrequest __P((int, struct rtentry *, struct sockaddr *));
        !           189: 
        !           190: int    ether_addmulti __P((struct ifreq *, struct arpcom *));
        !           191: int    ether_delmulti __P((struct ifreq *, struct arpcom *, struct ether_addr *));
        !           192: 
        !           193: /*
        !           194:  * Ethernet multicast address structure.  There is one of these for each
        !           195:  * multicast address or range of multicast addresses that we are supposed
        !           196:  * to listen to on a particular interface.  They are kept in a linked list,
        !           197:  * rooted in the interface's arpcom structure.  (This really has nothing to
        !           198:  * do with ARP, or with the Internet address family, but this appears to be
        !           199:  * the minimally-disrupting place to put it.)
        !           200:  */
        !           201: struct ether_multi {
        !           202:        u_char  enm_addrlo[6];          /* low  or only address of range */
        !           203:        u_char  enm_addrhi[6];          /* high or only address of range */
        !           204:        struct  arpcom *enm_ac;         /* back pointer to arpcom */
        !           205:        u_int   enm_refcount;           /* no. claims to this addr/range */
        !           206:        struct  ether_multi *enm_next;  /* ptr to next ether_multi */
        !           207: };
        !           208: 
        !           209: /*
        !           210:  * Structure used by macros below to remember position when stepping through
        !           211:  * all of the ether_multi records.
        !           212:  */
        !           213: struct ether_multistep {
        !           214:        struct ether_multi  *e_enm;
        !           215: };
        !           216: 
        !           217: /*
        !           218:  * Macro for looking up the ether_multi record for a given range of Ethernet
        !           219:  * multicast addresses connected to a given arpcom structure.  If no matching
        !           220:  * record is found, "enm" returns NULL.
        !           221:  */
        !           222: #define ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm) \
        !           223:        /* u_char addrlo[6]; */ \
        !           224:        /* u_char addrhi[6]; */ \
        !           225:        /* struct arpcom *ac; */ \
        !           226:        /* struct ether_multi *enm; */ \
        !           227: { \
        !           228:        for ((enm) = (ac)->ac_multiaddrs; \
        !           229:            (enm) != NULL && \
        !           230:            (bcmp((enm)->enm_addrlo, (addrlo), 6) != 0 || \
        !           231:             bcmp((enm)->enm_addrhi, (addrhi), 6) != 0); \
        !           232:                (enm) = (enm)->enm_next); \
        !           233: }
        !           234: 
        !           235: /*
        !           236:  * Macro to step through all of the ether_multi records, one at a time.
        !           237:  * The current position is remembered in "step", which the caller must
        !           238:  * provide.  ETHER_FIRST_MULTI(), below, must be called to initialize "step"
        !           239:  * and get the first record.  Both macros return a NULL "enm" when there
        !           240:  * are no remaining records.
        !           241:  */
        !           242: #define ETHER_NEXT_MULTI(step, enm) \
        !           243:        /* struct ether_multistep step; */  \
        !           244:        /* struct ether_multi *enm; */  \
        !           245: { \
        !           246:        if (((enm) = (step).e_enm) != NULL) \
        !           247:                (step).e_enm = (enm)->enm_next; \
        !           248: }
        !           249: 
        !           250: #define ETHER_FIRST_MULTI(step, ac, enm) \
        !           251:        /* struct ether_multistep step; */ \
        !           252:        /* struct arpcom *ac; */ \
        !           253:        /* struct ether_multi *enm; */ \
        !           254: { \
        !           255:        (step).e_enm = (ac)->ac_multiaddrs; \
        !           256:        ETHER_NEXT_MULTI((step), (enm)); \
        !           257: }
        !           258: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.