1GETIFADDRS(3)              Linux Programmer's Manual             GETIFADDRS(3)
2
3
4

NAME

6       getifaddrs, freeifaddrs - get interface addresses
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <ifaddrs.h>
11
12       int getifaddrs(struct ifaddrs **ifap);
13
14       void freeifaddrs(struct ifaddrs *ifa);
15

DESCRIPTION

17       The  getifaddrs() function creates a linked list of structures describ‐
18       ing the network interfaces of the local system, and stores the  address
19       of  the  first item of the list in *ifap.  The list consists of ifaddrs
20       structures, defined as follows:
21
22           struct ifaddrs {
23               struct ifaddrs  *ifa_next;    /* Next item in list */
24               char            *ifa_name;    /* Name of interface */
25               unsigned int     ifa_flags;   /* Flags from SIOCGIFFLAGS */
26               struct sockaddr *ifa_addr;    /* Address of interface */
27               struct sockaddr *ifa_netmask; /* Netmask of interface */
28               union {
29                   struct sockaddr *ifu_broadaddr;
30                                    /* Broadcast address of interface */
31                   struct sockaddr *ifu_dstaddr;
32                                    /* Point-to-point destination address */
33               } ifa_ifu;
34           #define              ifa_broadaddr ifa_ifu.ifu_broadaddr
35           #define              ifa_dstaddr   ifa_ifu.ifu_dstaddr
36               void            *ifa_data;    /* Address-specific data */
37           };
38
39       The ifa_next field contains a pointer to  the  next  structure  on  the
40       list, or NULL if this is the last item of the list.
41
42       The ifa_name points to the null-terminated interface name.
43
44       The  ifa_flags  field  contains the interface flags, as returned by the
45       SIOCGIFFLAGS ioctl(2) operation (see netdevice(7) for a list  of  these
46       flags).
47
48       The  ifa_addr  field  points  to  a  structure containing the interface
49       address.  (The sa_family subfield should be consulted to determine  the
50       format  of  the  address  structure.)   This  field  may contain a null
51       pointer.
52
53       The ifa_netmask field points to  a  structure  containing  the  netmask
54       associated  with  ifa_addr, if applicable for the address family.  This
55       field may contain a null pointer.
56
57       Depending on whether the bit IFF_BROADCAST or IFF_POINTOPOINT is set in
58       ifa_flags  (only  one  can be set at a time), either ifa_broadaddr will
59       contain the broadcast address associated with ifa_addr  (if  applicable
60       for  the  address  family)  or ifa_dstaddr will contain the destination
61       address of the point-to-point interface.
62
63       The ifa_data field points to a  buffer  containing  address-family-spe‐
64       cific  data;  this  field may be NULL if there is no such data for this
65       interface.
66
67       The data returned by getifaddrs() is dynamically allocated  and  should
68       be freed using freeifaddrs() when no longer needed.
69

RETURN VALUE

71       On  success,  getifaddrs()  returns zero; on error, -1 is returned, and
72       errno is set appropriately.
73

ERRORS

75       getifaddrs() may fail and set errno for any of the errors specified for
76       socket(2),  bind(2),  getsockname(2), recvmsg(2), sendto(2),