home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 19 / Amiga Plus Leser CD 19.iso / Tools / MorphOS / cvs-1.11.2 / source / amiga / netinclude / net / if.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-18  |  10.4 KB  |  272 lines

  1. /*
  2.  * Copyright (c) 1982, 1986, 1989, 1993
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    @(#)if.h    8.3 (Berkeley) 2/9/95
  34.  */
  35.  
  36. #ifndef _NET_IF_H
  37. #define _NET_IF_H
  38.  
  39. /*
  40.  * Structures defining a network interface, providing a packet
  41.  * transport mechanism (ala level 0 of the PUP protocols).
  42.  *
  43.  * Each interface accepts output datagrams of a specified maximum
  44.  * length, and provides higher level routines with input datagrams
  45.  * received from its medium.
  46.  *
  47.  * Output occurs when the routine if_output is called, with three parameters:
  48.  *    (*ifp->if_output)(ifp, m, dst, rt)
  49.  * Here m is the mbuf chain to be sent and dst is the destination address.
  50.  * The output routine encapsulates the supplied datagram if necessary,
  51.  * and then transmits it on its medium.
  52.  *
  53.  * On input, each interface unwraps the data received by it, and either
  54.  * places it on the input queue of a internetwork datagram routine
  55.  * and posts the associated software interrupt, or passes the datagram to a raw
  56.  * packet input routine.
  57.  *
  58.  * Routines exist for locating interfaces by their addresses
  59.  * or for locating a interface on a certain network, as well as more general
  60.  * routing and gateway routines maintaining information used to locate
  61.  * interfaces.  These routines live in the files if.c and route.c
  62.  */
  63.  
  64. #ifndef EXEC_TYPES_H
  65. #include <exec/types.h>
  66. #endif /* EXEC_TYPES_H */
  67.  
  68. #ifndef _SYS_SOCKET_H
  69. #include <sys/socket.h>
  70. #endif /* _SYS_SOCKET_H */
  71.  
  72. /*
  73.  * Structure describing information about an interface
  74.  * which may be of interest to management entities.
  75.  */
  76. /*
  77.  * Structure defining a queue for a network interface.
  78.  *
  79.  * (Would like to call this struct ``if'', but C isn't PL/1.)
  80.  */
  81.  
  82. struct ifnet {
  83.     STRPTR    if_name;        /* name, e.g. ``en'' or ``lo'' */
  84.     struct    ifnet *if_next;        /* all struct ifnets are chained */
  85.     struct    ifaddr *if_addrlist;    /* linked list of addresses per if */
  86.         LONG    if_pcount;        /* number of promiscuous listeners */
  87.     APTR    if_bpf;            /* packet filter structure */
  88.     UWORD    if_index;        /* numeric abbreviation for this if  */
  89.     WORD    if_unit;        /* sub-unit for lower level driver */
  90.     WORD    if_timer;        /* time 'til if_watchdog called */
  91.     UWORD    if_flags;        /* up/down, broadcast, etc. */
  92.     struct    if_data {
  93. /* generic interface information */
  94.         UBYTE    ifi_type;    /* ethernet, tokenring, etc */
  95.         UBYTE    ifi_addrlen;    /* media address length */
  96.         UBYTE    ifi_hdrlen;    /* media header length */
  97.         ULONG    ifi_mtu;    /* maximum transmission unit */
  98.         ULONG    ifi_metric;    /* routing metric (external only) */
  99.         ULONG    ifi_baudrate;    /* linespeed */
  100. /* volatile statistics */
  101.         ULONG    ifi_ipackets;    /* packets received on interface */
  102.         ULONG    ifi_ierrors;    /* input errors on interface */
  103.         ULONG    ifi_opackets;    /* packets sent on interface */
  104.         ULONG    ifi_oerrors;    /* output errors on interface */
  105.         ULONG    ifi_collisions;    /* collisions on csma interfaces */
  106.         ULONG    ifi_ibytes;    /* total number of octets received */
  107.         ULONG    ifi_obytes;    /* total number of octets sent */
  108.         ULONG    ifi_imcasts;    /* packets received via multicast */
  109.         ULONG    ifi_omcasts;    /* packets sent via multicast */
  110.         ULONG    ifi_iqdrops;    /* dropped on input, this interface */
  111.         ULONG    ifi_noproto;    /* destined for unsupported protocol */
  112.         struct    timeval ifi_lastchange;/* last updated */
  113.     }    if_data;
  114. /* procedure handles */
  115.     APTR    if_init;        /* init routine */
  116.     APTR    if_output;        /* output routine (enqueue) */
  117.     APTR    if_start;        /* initiate output routine */
  118.     APTR    if_done;        /* output complete routine */
  119.     APTR    if_ioctl;        /* ioctl routine */
  120.     APTR    if_reset;    
  121.     APTR    if_watchdog;        /* timer routine */
  122.     struct    ifqueue {
  123.         APTR    ifq_head;
  124.         APTR    ifq_tail;
  125.         LONG    ifq_len;
  126.         LONG    ifq_maxlen;
  127.         LONG    ifq_drops;
  128.     } if_snd;            /* output queue */
  129. };
  130. #define    if_mtu        if_data.ifi_mtu
  131. #define    if_type        if_data.ifi_type
  132. #define    if_addrlen    if_data.ifi_addrlen
  133. #define    if_hdrlen    if_data.ifi_hdrlen
  134. #define    if_metric    if_data.ifi_metric
  135. #define    if_baudrate    if_data.ifi_baudrate
  136. #define    if_ipackets    if_data.ifi_ipackets
  137. #define    if_ierrors    if_data.ifi_ierrors
  138. #define    if_opackets    if_data.ifi_opackets
  139. #define    if_oerrors    if_data.ifi_oerrors
  140. #define    if_collisions    if_data.ifi_collisions
  141. #define    if_ibytes    if_data.ifi_ibytes
  142. #define    if_obytes    if_data.ifi_obytes
  143. #define    if_imcasts    if_data.ifi_imcasts
  144. #define    if_omcasts    if_data.ifi_omcasts
  145. #define    if_iqdrops    if_data.ifi_iqdrops
  146. #define    if_noproto    if_data.ifi_noproto
  147. #define    if_lastchange    if_data.ifi_lastchange
  148.  
  149. #define    IFF_UP        0x1        /* interface is up */
  150. #define    IFF_BROADCAST    0x2        /* broadcast address valid */
  151. #define    IFF_DEBUG    0x4        /* turn on debugging */
  152. #define    IFF_LOOPBACK    0x8        /* is a loopback net */
  153. #define    IFF_POINTOPOINT    0x10        /* interface is point-to-point link */
  154. #define    IFF_NOTRAILERS    0x20        /* avoid use of trailers */
  155. #define    IFF_RUNNING    0x40        /* resources allocated */
  156. #define    IFF_NOARP    0x80        /* no address resolution protocol */
  157. #define    IFF_PROMISC    0x100        /* receive all packets */
  158. #define    IFF_ALLMULTI    0x200        /* receive all multicast packets */
  159. #define    IFF_OACTIVE    0x400        /* transmission in progress */
  160. #define    IFF_SIMPLEX    0x800        /* can't hear own transmissions */
  161. #define    IFF_LINK0    0x1000        /* per link layer defined bit */
  162. #define    IFF_LINK1    0x2000        /* per link layer defined bit */
  163. #define    IFF_LINK2    0x4000        /* per link layer defined bit */
  164. #define    IFF_MULTICAST    0x8000        /* supports multicast */
  165.  
  166. /* flags set internally only: */
  167. #define    IFF_CANTCHANGE \
  168.     (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
  169.         IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
  170.  
  171. /*
  172.  * The ifaddr structure contains information about one address
  173.  * of an interface.  They are maintained by the different address families,
  174.  * are allocated and attached when an address is set, and are linked
  175.  * together so all addresses for an interface can be located.
  176.  */
  177. struct ifaddr {
  178.     struct    sockaddr *ifa_addr;    /* address of interface */
  179.     struct    sockaddr *ifa_dstaddr;    /* other end of p-to-p link */
  180. #define    ifa_broadaddr    ifa_dstaddr    /* broadcast address interface */
  181.     struct    sockaddr *ifa_netmask;    /* used to determine subnet */
  182.     struct    ifnet *ifa_ifp;        /* back-pointer to interface */
  183.     struct    ifaddr *ifa_next;    /* next address for interface */
  184.     APTR    ifa_rtrequest;        /* check or clean routes (+ or -)'d */
  185.     UWORD    ifa_flags;        /* mostly rt_flags for cloning */
  186.     WORD    ifa_refcnt;        /* extra to malloc for link info */
  187.     LONG    ifa_metric;        /* cost of going out this interface */
  188. };
  189. #define    IFA_ROUTE    RTF_UP        /* route installed */
  190.  
  191. /*
  192.  * Message format for use in obtaining information about interfaces
  193.  * from getkerninfo and the routing socket
  194.  */
  195. struct if_msghdr {
  196.     UWORD    ifm_msglen;    /* to skip over non-understood messages */
  197.     UBYTE    ifm_version;    /* future binary compatability */
  198.     UBYTE    ifm_type;    /* message type */
  199.     LONG    ifm_addrs;    /* like rtm_addrs */
  200.     LONG    ifm_flags;    /* value of if_flags */
  201.     UWORD    ifm_index;    /* index for associated ifp */
  202.     struct    if_data ifm_data;/* statistics and other data about if */
  203. };
  204.  
  205. /*
  206.  * Message format for use in obtaining information about interface addresses
  207.  * from getkerninfo and the routing socket
  208.  */
  209. struct ifa_msghdr {
  210.     UWORD    ifam_msglen;    /* to skip over non-understood messages */
  211.     UBYTE    ifam_version;    /* future binary compatability */
  212.     UBYTE    ifam_type;    /* message type */
  213.     LONG    ifam_addrs;    /* like rtm_addrs */
  214.     LONG    ifam_flags;    /* value of ifa_flags */
  215.     UWORD    ifam_index;    /* index for associated ifp */
  216.     LONG    ifam_metric;    /* value of ifa_metric */
  217. };
  218.  
  219. /*
  220.  * Interface request structure used for socket
  221.  * ioctl's.  All interface ioctl's must have parameter
  222.  * definitions which begin with ifr_name.  The
  223.  * remainder may be interface specific.
  224.  */
  225. struct ifreq {
  226. #define    IFNAMSIZ    16
  227.     UBYTE    ifr_name[IFNAMSIZ];        /* if name, e.g. "en0" */
  228.     union {
  229.         struct    sockaddr ifru_addr;
  230.         struct    sockaddr ifru_dstaddr;
  231.         struct    sockaddr ifru_broadaddr;
  232.         WORD    ifru_flags;
  233.         LONG    ifru_metric;
  234.         APTR    ifru_data;
  235.     } ifr_ifru;
  236. #define    ifr_addr    ifr_ifru.ifru_addr    /* address */
  237. #define    ifr_dstaddr    ifr_ifru.ifru_dstaddr    /* other end of p-to-p link */
  238. #define    ifr_broadaddr    ifr_ifru.ifru_broadaddr    /* broadcast address */
  239. #define    ifr_flags    ifr_ifru.ifru_flags    /* flags */
  240. #define    ifr_metric    ifr_ifru.ifru_metric    /* metric */
  241. #define    ifr_data    ifr_ifru.ifru_data    /* for use by interface */
  242. };
  243.  
  244. struct ifaliasreq {
  245.     UBYTE    ifra_name[IFNAMSIZ];        /* if name, e.g. "en0" */
  246.     struct    sockaddr ifra_addr;
  247.     struct    sockaddr ifra_broadaddr;
  248.     struct    sockaddr ifra_mask;
  249. };
  250.  
  251. /*
  252.  * Structure used in SIOCGIFCONF request.
  253.  * Used to retrieve interface configuration
  254.  * for machine (useful for programs which
  255.  * must know all networks accessible).
  256.  */
  257. struct    ifconf {
  258.     LONG    ifc_len;        /* size of associated buffer */
  259.     union {
  260.         APTR    ifcu_buf;
  261.         struct    ifreq *ifcu_req;
  262.     } ifc_ifcu;
  263. #define    ifc_buf    ifc_ifcu.ifcu_buf    /* buffer address */
  264. #define    ifc_req    ifc_ifcu.ifcu_req    /* array of structures returned */
  265. };
  266.  
  267. #ifndef _NET_IF_ARP_H
  268. #include <net/if_arp.h>
  269. #endif /* _NET_IF_ARP_H */
  270.  
  271. #endif /* _NET_IF_H */
  272.