home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / darwin / darwinx86.iso / usr / include / net / if.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-30  |  9.5 KB  |  287 lines

  1. /*
  2.  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
  3.  *
  4.  * @APPLE_LICENSE_HEADER_START@
  5.  * 
  6.  * The contents of this file constitute Original Code as defined in and
  7.  * are subject to the Apple Public Source License Version 1.1 (the
  8.  * "License").  You may not use this file except in compliance with the
  9.  * License.  Please obtain a copy of the License at
  10.  * http://www.apple.com/publicsource and read it before using this file.
  11.  * 
  12.  * This Original Code and all software distributed under the License are
  13.  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  14.  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  15.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  16.  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
  17.  * License for the specific language governing rights and limitations
  18.  * under the License.
  19.  * 
  20.  * @APPLE_LICENSE_HEADER_END@
  21.  */
  22. /*
  23.  * Copyright (c) 1982, 1986, 1989, 1993
  24.  *    The Regents of the University of California.  All rights reserved.
  25.  *
  26.  * Redistribution and use in source and binary forms, with or without
  27.  * modification, are permitted provided that the following conditions
  28.  * are met:
  29.  * 1. Redistributions of source code must retain the above copyright
  30.  *    notice, this list of conditions and the following disclaimer.
  31.  * 2. Redistributions in binary form must reproduce the above copyright
  32.  *    notice, this list of conditions and the following disclaimer in the
  33.  *    documentation and/or other materials provided with the distribution.
  34.  * 3. All advertising materials mentioning features or use of this software
  35.  *    must display the following acknowledgement:
  36.  *    This product includes software developed by the University of
  37.  *    California, Berkeley and its contributors.
  38.  * 4. Neither the name of the University nor the names of its contributors
  39.  *    may be used to endorse or promote products derived from this software
  40.  *    without specific prior written permission.
  41.  *
  42.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  43.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  44.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  45.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  46.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  47.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  48.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  49.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  50.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  51.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  52.  * SUCH DAMAGE.
  53.  *
  54.  *    @(#)if.h    8.1 (Berkeley) 6/10/93
  55.  */
  56.  
  57. #ifndef _NET_IF_H_
  58. #define    _NET_IF_H_
  59.  
  60.  
  61. /*
  62.  * Define Data-Link event subclass, and associated
  63.  * events.
  64.  */
  65.  
  66. #define KEV_DL_SUBCLASS 2
  67.  
  68. #define KEV_DL_SIFFLAGS        1
  69. #define KEV_DL_SIFMETRICS   2
  70. #define KEV_DL_SIFMTU        3
  71. #define KEV_DL_SIFPHYS        4
  72. #define KEV_DL_SIFMEDIA        5
  73. #define KEV_DL_SIFGENERIC   6
  74. #define KEV_DL_ADDMULTI        7
  75. #define KEV_DL_DELMULTI        8
  76. #define KEV_DL_IF_ATTACHED  9
  77. #define KEV_DL_IF_DETACHING 10
  78. #define KEV_DL_IF_DETACHED  11
  79. #define KEV_DL_LINK_OFF        12
  80. #define KEV_DL_LINK_ON        13
  81. #define KEV_DL_PROTO_ATTACHED    14
  82. #define KEV_DL_PROTO_DETACHED    15
  83.  
  84. /*
  85.  * <net/if.h> does not depend on <sys/time.h> on most other systems.  This
  86.  * helps userland compatability.  (struct timeval ifi_lastchange)
  87.  */
  88.  
  89. #include <sys/time.h>
  90. #include <net/if_var.h>
  91.  
  92.  
  93. #define    IFF_UP        0x1        /* interface is up */
  94. #define    IFF_BROADCAST    0x2        /* broadcast address valid */
  95. #define    IFF_DEBUG    0x4        /* turn on debugging */
  96. #define    IFF_LOOPBACK    0x8        /* is a loopback net */
  97. #define    IFF_POINTOPOINT    0x10        /* interface is point-to-point link */
  98. #define IFF_NOTRAILERS 0x20        /* obsolete: avoid use of trailers */
  99. #define    IFF_RUNNING    0x40        /* resources allocated */
  100. #define    IFF_NOARP    0x80        /* no address resolution protocol */
  101. #define    IFF_PROMISC    0x100        /* receive all packets */
  102. #define    IFF_ALLMULTI    0x200        /* receive all multicast packets */
  103. #define    IFF_OACTIVE    0x400        /* transmission in progress */
  104. #define    IFF_SIMPLEX    0x800        /* can't hear own transmissions */
  105. #define    IFF_LINK0    0x1000        /* per link layer defined bit */
  106. #define    IFF_LINK1    0x2000        /* per link layer defined bit */
  107. #define    IFF_LINK2    0x4000        /* per link layer defined bit */
  108. #define    IFF_ALTPHYS    IFF_LINK2    /* use alternate physical connection */
  109. #define    IFF_MULTICAST    0x8000        /* supports multicast */
  110. #define IFF_SPLITTER    IFF_LINK2    /* Y splitter in force */
  111.  
  112.  
  113.  
  114. /* flags set internally only: */
  115. #define    IFF_CANTCHANGE \
  116.     (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
  117.         IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
  118.  
  119. #define    IFQ_MAXLEN    50
  120. #define    IFNET_SLOWHZ    1        /* granularity is 1 second */
  121.  
  122. /*
  123.  * Message format for use in obtaining information about interfaces
  124.  * from getkerninfo and the routing socket
  125.  */
  126. struct if_msghdr {
  127.     u_short    ifm_msglen;    /* to skip over non-understood messages */
  128.     u_char    ifm_version;    /* future binary compatability */
  129.     u_char    ifm_type;    /* message type */
  130.     int    ifm_addrs;    /* like rtm_addrs */
  131.     int    ifm_flags;    /* value of if_flags */
  132.     u_short    ifm_index;    /* index for associated ifp */
  133.     struct    if_data ifm_data;/* statistics and other data about if */
  134. };
  135.  
  136. /*
  137.  * Message format for use in obtaining information about interface addresses
  138.  * from getkerninfo and the routing socket
  139.  */
  140. struct ifa_msghdr {
  141.     u_short    ifam_msglen;    /* to skip over non-understood messages */
  142.     u_char    ifam_version;    /* future binary compatability */
  143.     u_char    ifam_type;    /* message type */
  144.     int    ifam_addrs;    /* like rtm_addrs */
  145.     int    ifam_flags;    /* value of ifa_flags */
  146.     u_short    ifam_index;    /* index for associated ifp */
  147.     int    ifam_metric;    /* value of ifa_metric */
  148. };
  149.  
  150. /*
  151.  * Message format for use in obtaining information about multicast addresses
  152.  * from the routing socket
  153.  */
  154. struct ifma_msghdr {
  155.     u_short    ifmam_msglen;    /* to skip over non-understood messages */
  156.     u_char    ifmam_version;    /* future binary compatability */
  157.     u_char    ifmam_type;    /* message type */
  158.     int    ifmam_addrs;    /* like rtm_addrs */
  159.     int    ifmam_flags;    /* value of ifa_flags */
  160.     u_short    ifmam_index;    /* index for associated ifp */
  161. };
  162.  
  163. /*
  164.  * Interface request structure used for socket
  165.  * ioctl's.  All interface ioctl's must have parameter
  166.  * definitions which begin with ifr_name.  The
  167.  * remainder may be interface specific.
  168.  */
  169. #define    IF_NAMESIZE    IFNAMSIZ
  170. struct    ifreq {
  171. #define    IFNAMSIZ    16
  172.     char    ifr_name[IFNAMSIZ];        /* if name, e.g. "en0" */
  173.     union {
  174.         struct    sockaddr ifru_addr;
  175.         struct    sockaddr ifru_dstaddr;
  176.         struct    sockaddr ifru_broadaddr;
  177.         short    ifru_flags;
  178.         int    ifru_metric;
  179.         int    ifru_mtu;
  180.         int    ifru_phys;
  181.         int    ifru_media;
  182.         caddr_t    ifru_data;
  183.     } ifr_ifru;
  184. #define    ifr_addr    ifr_ifru.ifru_addr    /* address */
  185. #define    ifr_dstaddr    ifr_ifru.ifru_dstaddr    /* other end of p-to-p link */
  186. #define    ifr_broadaddr    ifr_ifru.ifru_broadaddr    /* broadcast address */
  187. #define    ifr_flags    ifr_ifru.ifru_flags    /* flags */
  188. #define    ifr_metric    ifr_ifru.ifru_metric    /* metric */
  189. #define    ifr_mtu        ifr_ifru.ifru_mtu    /* mtu */
  190. #define ifr_phys    ifr_ifru.ifru_phys    /* physical wire */
  191. #define ifr_media    ifr_ifru.ifru_media    /* physical media */
  192. #define    ifr_data    ifr_ifru.ifru_data    /* for use by interface */
  193. };
  194.  
  195. #define    _SIZEOF_ADDR_IFREQ(ifr) \
  196.     ((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \
  197.      (sizeof(struct ifreq) - sizeof(struct sockaddr) + \
  198.       (ifr).ifr_addr.sa_len) : sizeof(struct ifreq))
  199.  
  200. struct ifaliasreq {
  201.     char    ifra_name[IFNAMSIZ];        /* if name, e.g. "en0" */
  202.     struct    sockaddr ifra_addr;
  203.     struct    sockaddr ifra_broadaddr;
  204.     struct    sockaddr ifra_mask;
  205. };
  206.  
  207. struct rslvmulti_req {
  208.      struct sockaddr *sa;
  209.      struct sockaddr **llsa;
  210. };
  211.  
  212. struct ifmediareq {
  213.     char    ifm_name[IFNAMSIZ];    /* if name, e.g. "en0" */
  214.     int    ifm_current;        /* current media options */
  215.     int    ifm_mask;        /* don't care mask */
  216.     int    ifm_status;        /* media status */
  217.     int    ifm_active;        /* active options */
  218.     int    ifm_count;        /* # entries in ifm_ulist array */
  219.     int    *ifm_ulist;        /* media words */
  220. };
  221. /*
  222.  * Structure used in SIOCGIFCONF request.
  223.  * Used to retrieve interface configuration
  224.  * for machine (useful for programs which
  225.  * must know all networks accessible).
  226.  */
  227. struct    ifconf {
  228.     int    ifc_len;        /* size of associated buffer */
  229.     union {
  230.         caddr_t    ifcu_buf;
  231.         struct    ifreq *ifcu_req;
  232.     } ifc_ifcu;
  233. #define    ifc_buf    ifc_ifcu.ifcu_buf    /* buffer address */
  234. #define    ifc_req    ifc_ifcu.ifcu_req    /* array of structures returned */
  235. };
  236.  
  237. /*
  238.  * DLIL KEV_DL_PROTO_ATTACHED/DETACHED structure
  239.  */
  240. struct kev_dl_proto_data {
  241.      struct net_event_data       link_data;
  242.      u_long            proto_family;
  243.      u_long            proto_remaining_count;
  244. };
  245.  
  246.  
  247. /*
  248.  * Structure for SIOC[AGD]LIFADDR
  249.  */
  250. struct if_laddrreq {
  251.     char iflr_name[IFNAMSIZ];
  252.     unsigned int flags;
  253. #define IFLR_PREFIX    0x8000  /* in: prefix given  out: kernel fills id */
  254.     unsigned int prefixlen;         /* in/out */
  255.     struct sockaddr_storage addr;   /* in/out */
  256.     struct sockaddr_storage dstaddr; /* out */
  257. };
  258.  
  259.  
  260. #ifdef KERNEL
  261. #ifdef MALLOC_DECLARE
  262. MALLOC_DECLARE(M_IFADDR);
  263. MALLOC_DECLARE(M_IFMADDR);
  264. #endif
  265. #endif
  266.  
  267. #ifndef KERNEL
  268. struct if_nameindex { 
  269.         unsigned int    if_index;       /* 1, 2, ... */
  270.         char            *if_name;       /* null terminated name: "le0", ... */
  271. };      
  272.  
  273. __BEGIN_DECLS
  274. unsigned int if_nametoindex __P((const char *));
  275. char *if_indextoname __P((unsigned int, char *));
  276. struct if_nameindex *if_nameindex __P((void));
  277. void if_freenameindex __P((struct if_nameindex *));
  278. __END_DECLS
  279. #endif
  280.  
  281. /* XXX - this should go away soon */
  282. #ifdef KERNEL
  283. #include <net/if_var.h>
  284. #endif
  285.  
  286. #endif /* !_NET_IF_H_ */
  287.