Back to index

glibc  2.9
if.h
Go to the documentation of this file.
00001 /* net/if.h -- declarations for inquiring about network interfaces
00002    Copyright (C) 1997,98,99,2000,2001 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef _NET_IF_H
00021 #define _NET_IF_H    1
00022 
00023 #include <features.h>
00024 
00025 #ifdef __USE_MISC
00026 # include <sys/types.h>
00027 # include <sys/socket.h>
00028 #endif
00029 
00030 
00031 /* Length of interface name.  */
00032 #define IF_NAMESIZE  16
00033 
00034 struct if_nameindex
00035   {
00036     unsigned int if_index;  /* 1, 2, ... */
00037     char *if_name;          /* null terminated name: "eth0", ... */
00038   };
00039 
00040 
00041 #ifdef __USE_MISC
00042 /* Standard interface flags. */
00043 enum
00044   {
00045     IFF_UP = 0x1,           /* Interface is up.  */
00046 # define IFF_UP      IFF_UP
00047     IFF_BROADCAST = 0x2,    /* Broadcast address valid.  */
00048 # define IFF_BROADCAST      IFF_BROADCAST
00049     IFF_DEBUG = 0x4,        /* Turn on debugging.  */
00050 # define IFF_DEBUG   IFF_DEBUG
00051     IFF_LOOPBACK = 0x8,            /* Is a loopback net.  */
00052 # define IFF_LOOPBACK       IFF_LOOPBACK
00053     IFF_POINTOPOINT = 0x10, /* Interface is point-to-point link.  */
00054 # define IFF_POINTOPOINT IFF_POINTOPOINT
00055     IFF_NOTRAILERS = 0x20,  /* Avoid use of trailers.  */
00056 # define IFF_NOTRAILERS     IFF_NOTRAILERS
00057     IFF_RUNNING = 0x40,            /* Resources allocated.  */
00058 # define IFF_RUNNING IFF_RUNNING
00059     IFF_NOARP = 0x80,              /* No address resolution protocol.  */
00060 # define IFF_NOARP   IFF_NOARP
00061     IFF_PROMISC = 0x100,    /* Receive all packets.  */
00062 # define IFF_PROMISC IFF_PROMISC
00063 
00064     /* Not supported */
00065     IFF_ALLMULTI = 0x200,   /* Receive all multicast packets.  */
00066 # define IFF_ALLMULTI       IFF_ALLMULTI
00067 
00068     IFF_MASTER = 0x400,            /* Master of a load balancer.  */
00069 # define IFF_MASTER  IFF_MASTER
00070     IFF_SLAVE = 0x800,             /* Slave of a load balancer.  */
00071 # define IFF_SLAVE   IFF_SLAVE
00072 
00073     IFF_MULTICAST = 0x1000, /* Supports multicast.  */
00074 # define IFF_MULTICAST      IFF_MULTICAST
00075 
00076     IFF_PORTSEL = 0x2000,   /* Can set media type.  */
00077 # define IFF_PORTSEL IFF_PORTSEL
00078     IFF_AUTOMEDIA = 0x4000, /* Auto media select active.  */
00079 # define IFF_AUTOMEDIA      IFF_AUTOMEDIA
00080     IFF_DYNAMIC = 0x8000    /* Dialup device with changing addresses.  */
00081 # define IFF_DYNAMIC IFF_DYNAMIC
00082   };
00083 
00084 /* The ifaddr structure contains information about one address of an
00085    interface.  They are maintained by the different address families,
00086    are allocated and attached when an address is set, and are linked
00087    together so all addresses for an interface can be located.  */
00088 
00089 struct ifaddr
00090   {
00091     struct sockaddr ifa_addr;      /* Address of interface.  */
00092     union
00093       {
00094        struct sockaddr      ifu_broadaddr;
00095        struct sockaddr      ifu_dstaddr;
00096       } ifa_ifu;
00097     struct iface *ifa_ifp;  /* Back-pointer to interface.  */
00098     struct ifaddr *ifa_next;       /* Next address for interface.  */
00099   };
00100 
00101 # define ifa_broadaddr      ifa_ifu.ifu_broadaddr       /* broadcast address */
00102 # define ifa_dstaddr ifa_ifu.ifu_dstaddr  /* other end of link */
00103 
00104 /* Device mapping structure. I'd just gone off and designed a
00105    beautiful scheme using only loadable modules with arguments for
00106    driver options and along come the PCMCIA people 8)
00107 
00108    Ah well. The get() side of this is good for WDSETUP, and it'll be
00109    handy for debugging things. The set side is fine for now and being
00110    very small might be worth keeping for clean configuration.  */
00111 
00112 struct ifmap
00113   {
00114     unsigned long int mem_start;
00115     unsigned long int mem_end;
00116     unsigned short int base_addr;
00117     unsigned char irq;
00118     unsigned char dma;
00119     unsigned char port;
00120     /* 3 bytes spare */
00121   };
00122 
00123 /* Interface request structure used for socket ioctl's.  All interface
00124    ioctl's must have parameter definitions which begin with ifr_name.
00125    The remainder may be interface specific.  */
00126 
00127 struct ifreq
00128   {
00129 # define IFHWADDRLEN 6
00130 # define IFNAMSIZ    IF_NAMESIZE
00131     union
00132       {
00133        char ifrn_name[IFNAMSIZ];   /* Interface name, e.g. "en0".  */
00134       } ifr_ifrn;
00135 
00136     union
00137       {
00138        struct sockaddr ifru_addr;
00139        struct sockaddr ifru_dstaddr;
00140        struct sockaddr ifru_broadaddr;
00141        struct sockaddr ifru_netmask;
00142        struct sockaddr ifru_hwaddr;
00143        short int ifru_flags;
00144        int ifru_ivalue;
00145        int ifru_mtu;
00146        struct ifmap ifru_map;
00147        char ifru_slave[IFNAMSIZ];  /* Just fits the size */
00148        char ifru_newname[IFNAMSIZ];
00149        __caddr_t ifru_data;
00150       } ifr_ifru;
00151   };
00152 # define ifr_name    ifr_ifrn.ifrn_name   /* interface name    */
00153 # define ifr_hwaddr  ifr_ifru.ifru_hwaddr /* MAC address              */
00154 # define ifr_addr    ifr_ifru.ifru_addr   /* address           */
00155 # define ifr_dstaddr ifr_ifru.ifru_dstaddr       /* other end of p-p lnk     */
00156 # define ifr_broadaddr      ifr_ifru.ifru_broadaddr     /* broadcast address */
00157 # define ifr_netmask ifr_ifru.ifru_netmask       /* interface net mask       */
00158 # define ifr_flags   ifr_ifru.ifru_flags  /* flags             */
00159 # define ifr_metric  ifr_ifru.ifru_ivalue /* metric            */
00160 # define ifr_mtu     ifr_ifru.ifru_mtu    /* mtu               */
00161 # define ifr_map     ifr_ifru.ifru_map    /* device map        */
00162 # define ifr_slave   ifr_ifru.ifru_slave  /* slave device             */
00163 # define ifr_data    ifr_ifru.ifru_data   /* for use by interface     */
00164 # define ifr_ifindex ifr_ifru.ifru_ivalue    /* interface index      */
00165 # define ifr_bandwidth      ifr_ifru.ifru_ivalue /* link bandwidth    */
00166 # define ifr_qlen    ifr_ifru.ifru_ivalue /* queue length             */
00167 # define ifr_newname ifr_ifru.ifru_newname       /* New name          */
00168 # define _IOT_ifreq  _IOT(_IOTS(char),IFNAMSIZ,_IOTS(char),16,0,0)
00169 # define _IOT_ifreq_short _IOT(_IOTS(char),IFNAMSIZ,_IOTS(short),1,0,0)
00170 # define _IOT_ifreq_int     _IOT(_IOTS(char),IFNAMSIZ,_IOTS(int),1,0,0)
00171 
00172 
00173 /* Structure used in SIOCGIFCONF request.  Used to retrieve interface
00174    configuration for machine (useful for programs which must know all
00175    networks accessible).  */
00176 
00177 struct ifconf
00178   {
00179     int       ifc_len;                    /* Size of buffer.  */
00180     union
00181       {
00182        __caddr_t ifcu_buf;
00183        struct ifreq *ifcu_req;
00184       } ifc_ifcu;
00185   };
00186 # define ifc_buf     ifc_ifcu.ifcu_buf    /* Buffer address.  */
00187 # define ifc_req     ifc_ifcu.ifcu_req    /* Array of structures.  */
00188 # define _IOT_ifconf _IOT(_IOTS(struct ifconf),1,0,0,0,0) /* not right */
00189 #endif /* Misc.  */
00190 
00191 __BEGIN_DECLS
00192 
00193 /* Convert an interface name to an index, and vice versa.  */
00194 extern unsigned int if_nametoindex (__const char *__ifname) __THROW;
00195 extern char *if_indextoname (unsigned int __ifindex, char *__ifname) __THROW;
00196 
00197 /* Return a list of all interfaces and their indices.  */
00198 extern struct if_nameindex *if_nameindex (void) __THROW;
00199 
00200 /* Free the data returned from if_nameindex.  */
00201 extern void if_freenameindex (struct if_nameindex *__ptr) __THROW;
00202 
00203 __END_DECLS
00204 
00205 #endif /* net/if.h */