Back to index

glibc  2.9
ifaddrs.h
Go to the documentation of this file.
00001 /* ifaddrs.h -- declarations for getting network interface addresses
00002    Copyright (C) 2002 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 _IFADDRS_H
00021 #define _IFADDRS_H   1
00022 
00023 #include <features.h>
00024 #include <sys/socket.h>
00025 
00026 __BEGIN_DECLS
00027 
00028 /* The `getifaddrs' function generates a linked list of these structures.
00029    Each element of the list describes one network interface.  */
00030 struct ifaddrs
00031 {
00032   struct ifaddrs *ifa_next; /* Pointer to the next structure.  */
00033 
00034   char *ifa_name;           /* Name of this network interface.  */
00035   unsigned int ifa_flags;   /* Flags as from SIOCGIFFLAGS ioctl.  */
00036 
00037   struct sockaddr *ifa_addr;       /* Network address of this interface.  */
00038   struct sockaddr *ifa_netmask; /* Netmask of this interface.  */
00039   union
00040   {
00041     /* At most one of the following two is valid.  If the IFF_BROADCAST
00042        bit is set in `ifa_flags', then `ifa_broadaddr' is valid.  If the
00043        IFF_POINTOPOINT bit is set, then `ifa_dstaddr' is valid.
00044        It is never the case that both these bits are set at once.  */
00045     struct sockaddr *ifu_broadaddr; /* Broadcast address of this interface. */
00046     struct sockaddr *ifu_dstaddr; /* Point-to-point destination address.  */
00047   } ifa_ifu;
00048   /* These very same macros are defined by <net/if.h> for `struct ifaddr'.
00049      So if they are defined already, the existing definitions will be fine.  */
00050 # ifndef ifa_broadaddr
00051 #  define ifa_broadaddr     ifa_ifu.ifu_broadaddr
00052 # endif
00053 # ifndef ifa_dstaddr
00054 #  define ifa_dstaddr       ifa_ifu.ifu_dstaddr
00055 # endif
00056 
00057   void *ifa_data;           /* Address-specific data (may be unused).  */
00058 };
00059 
00060 
00061 /* Create a linked list of `struct ifaddrs' structures, one for each
00062    network interface on the host machine.  If successful, store the
00063    list in *IFAP and return 0.  On errors, return -1 and set `errno'.
00064 
00065    The storage returned in *IFAP is allocated dynamically and can
00066    only be properly freed by passing it to `freeifaddrs'.  */
00067 extern int getifaddrs (struct ifaddrs **__ifap) __THROW;
00068 
00069 /* Reclaim the storage allocated by a previous `getifaddrs' call.  */
00070 extern void freeifaddrs (struct ifaddrs *__ifa)  __THROW;
00071 
00072 __END_DECLS
00073 
00074 #endif /* ifaddrs.h */