Back to index

glibc  2.9
if.h
Go to the documentation of this file.
00001 /* Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #ifndef _NET_IF_H
00020 
00021 #define _NET_IF_H    1
00022 #include <features.h>
00023 
00024 #include <sys/types.h>
00025 #include <sys/socket.h>
00026 
00027 /* Standard interface flags. */
00028 enum
00029   {
00030     IFF_UP = 0x1,           /* Interface is up.  */
00031 #define IFF_UP       IFF_UP
00032     IFF_BROADCAST = 0x2,    /* Broadcast address valid.  */
00033 #define IFF_BROADCAST       IFF_BROADCAST
00034     IFF_DEBUG = 0x4,        /* Turn on debugging.  */
00035 #define IFF_DEBUG    IFF_DEBUG
00036     IFF_LOOPBACK = 0x8,            /* Is a loopback net.  */
00037 #define IFF_LOOPBACK IFF_LOOPBACK
00038     IFF_POINTOPOINT = 0x10, /* Interface is point-to-point link.  */
00039 #define IFF_POINTOPOINT     IFF_POINTOPOINT
00040     IFF_NOTRAILERS = 0x20,  /* Avoid use of trailers.  */
00041 #define IFF_NOTRAILERS      IFF_NOTRAILERS
00042     IFF_RUNNING = 0x40,            /* Resources allocated.  */
00043 #define IFF_RUNNING  IFF_RUNNING
00044     IFF_NOARP = 0x80,              /* No address resolution protocol.  */
00045 #define IFF_NOARP    IFF_NOARP
00046     IFF_PROMISC = 0x100,    /* Receive all packets.  */
00047 #define IFF_PROMISC  IFF_PROMISC
00048 
00049     /* Not supported */
00050     IFF_ALLMULTI = 0x200,   /* Receive all multicast packets.  */
00051 #define IFF_ALLMULTI IFF_ALLMULTI
00052 
00053     IFF_OACTIVE = 0x400,    /* Transmission in progress.  */
00054 #define IFF_OACTIVE  IFF_OACTIVE
00055     IFF_SIMPLEX = 0x800,    /* Cannot hear own transmissions.  */
00056 #define IFF_SIMPLEX  IFF_SIMPLEX
00057     IFF_DO_HW_LOOPBACK = 0x10000, /* Force loopback through hardware.  */
00058 #define IFF_DO_HW_LOOPBACK  IFF_DO_HW_LOOPBACK
00059     IFF_ALLCAST = 0x20000,  /* Global broadcast.  */
00060 #define IFF_ALLCAST  IFF_ALLCAST
00061     IFF_BRIDGE = 0x40000,   /* Receive all bridge packets.  */
00062 #define IFF_BRIDGE   IFF_BRIDGE
00063     IFF_NOECHO = IFF_SIMPLEX,      /* Reeives echo packets.  */
00064 #define IFF_NOECHO   IFF_NOECHO
00065   };
00066 
00067 /* The ifaddr structure contains information about one address of an
00068    interface.  They are maintained by the different address families,
00069    are allocated and attached when an address is set, and are linked
00070    together so all addresses for an interface can be located.  */
00071 
00072 struct ifaddr
00073   {
00074     struct sockaddr ifa_addr;      /* Address of interface.  */
00075     union
00076       {
00077        struct sockaddr      ifu_broadaddr;
00078        struct sockaddr      ifu_dstaddr;
00079       } ifa_ifu;
00080     struct sockaddr *ifa_netmask; /* Used to determine subnet.  */
00081     struct iface *ifa_ifp;  /* Back-pointer to interface.  */
00082     struct ifaddr *ifa_next;       /* Next address for interface.  */
00083     void (*ifa_rtrequest) (void);
00084     struct rtentry *ifa_rt;
00085     unsigned short int ifa_flags;
00086     short int ifa_refcnt;
00087   };
00088 
00089 #define       ifa_broadaddr ifa_ifu.ifu_broadaddr       /* broadcast address */
00090 #define       ifa_dstaddr   ifa_ifu.ifu_dstaddr  /* other end of link */
00091 
00092 /* Interface request structure used for socket ioctl's.  All interface
00093    ioctl's must have parameter definitions which begin with ifr_name.
00094    The remainder may be interface specific.  */
00095 
00096 struct ifreq
00097   {
00098 #define IFHWADDRLEN  6
00099 #define       IFNAMSIZ      16
00100     union
00101       {
00102        char ifrn_name[IFNAMSIZ];   /* Interface name, e.g. "en0".  */
00103       } ifr_ifrn;
00104 
00105     union
00106       {
00107        struct sockaddr ifru_addr;
00108        struct sockaddr ifru_dstaddr;
00109        struct sockaddr ifru_broadaddr;
00110        struct sockaddr ifru_netmask;
00111        struct sockaddr ifru_hwaddr;
00112        short int ifru_flags;
00113        int ifru_ivalue;
00114        unsigned int ifru_mtu;
00115        char ifru_slave[IFNAMSIZ];  /* Just fits the size */
00116        __caddr_t ifru_data;
00117        unsigned short int ifru_site6;
00118       } ifr_ifru;
00119   };
00120 
00121 /* Old AIX 3.1 version.  */
00122 struct oifreq
00123 {
00124   char ifr_name[IFNAMSIZ];         /* if name, e.g. "en0" */
00125   union
00126   {
00127     struct  sockaddr ifru_addr;
00128     struct  sockaddr ifru_dstaddr;
00129     struct  sockaddr ifru_broadaddr;
00130     int ifru_flags;
00131     int ifru_metric;
00132     caddr_t ifru_data;
00133     unsigned int ifru_mtu;
00134   } ifr_ifru;
00135   unsigned char reserved[8];
00136 };
00137 
00138 
00139 #define ifr_name     ifr_ifrn.ifrn_name   /* interface name    */
00140 #define ifr_hwaddr   ifr_ifru.ifru_hwaddr /* MAC address              */
00141 #define       ifr_addr      ifr_ifru.ifru_addr   /* address           */
00142 #define       ifr_dstaddr   ifr_ifru.ifru_dstaddr       /* other end of p-p lnk     */
00143 #define       ifr_broadaddr ifr_ifru.ifru_broadaddr     /* broadcast address */
00144 #define       ifr_netmask   ifr_ifru.ifru_netmask       /* interface net mask       */
00145 #define       ifr_flags     ifr_ifru.ifru_flags  /* flags             */
00146 #define       ifr_metric    ifr_ifru.ifru_ivalue /* metric            */
00147 #define       ifr_mtu              ifr_ifru.ifru_mtu    /* mtu               */
00148 #define ifr_slave    ifr_ifru.ifru_slave  /* slave device             */
00149 #define       ifr_data      ifr_ifru.ifru_data   /* for use by interface     */
00150 #define ifr_ifindex  ifr_ifru.ifru_ivalue    /* interface index      */
00151 #define ifr_bandwidth       ifr_ifru.ifru_ivalue /* link bandwidth    */
00152 #define ifr_baudrate ifr_ifru.ifru_ivalue /* link bandwidth    */
00153 #define ifr_qlen     ifr_ifru.ifru_ivalue /* queue length             */
00154 #define ifr_site6    ifr_ifru.ifru_site6  /* IPv6 site index      */
00155 
00156 
00157 /* Structure used in SIOCGIFCONF request.  Used to retrieve interface
00158    configuration for machine (useful for programs which must know all
00159    networks accessible).  */
00160 
00161 struct ifconf
00162   {
00163     int       ifc_len;                    /* Size of buffer.  */
00164     union
00165       {
00166        __caddr_t ifcu_buf;
00167        struct ifreq *ifcu_req;
00168       } ifc_ifcu;
00169   };
00170 #define       ifc_buf       ifc_ifcu.ifcu_buf    /* Buffer address.  */
00171 #define       ifc_req       ifc_ifcu.ifcu_req    /* Array of structures.  */
00172 
00173 __BEGIN_DECLS
00174 
00175 /* Convert an interface name to an index, and vice versa.  */
00176 
00177 extern unsigned int if_nametoindex (__const char *__ifname) __THROW;
00178 extern char *if_indextoname (unsigned int __ifindex, char *__ifname) __THROW;
00179 
00180 /* Return a list of all interfaces and their indices.  */
00181 
00182 struct if_nameindex
00183   {
00184     unsigned int if_index;  /* 1, 2, ... */
00185     char *if_name;          /* null terminated name: "eth0", ... */
00186   };
00187 
00188 extern struct if_nameindex *if_nameindex (void) __THROW;
00189 
00190 /* Free the data returned from if_nameindex.  */
00191 
00192 extern void if_freenameindex (struct if_nameindex *__ptr) __THROW;
00193 
00194 __END_DECLS
00195 
00196 #endif /* net/if.h */