3 .\" This file and its contents are supplied under the terms of the
4 .\" Common Development and Distribution License ("CDDL"), version 1.0.
5 .\" You may only use this file in accordance with the terms of version
8 .\" A full copy of the text of the CDDL should have accompanied this
9 .\" source. A copy of the CDDL is also available via the Internet at
10 .\" http://www.illumos.org/license/CDDL.
13 .\" Copyright (c) 2013, Joyent, Inc. All rights reserved.
15 .TH GETIFADDRS 3SOCKET "Apr 18, 2013"
17 getifaddrs, freeifaddrs \- get interface addresses
21 \fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lsocket\fR \fB-lnsl\fR \
23 #include <sys/types.h>
24 #include <sys/socket.h>
30 \fBint\fR \fBgetifaddrs\fR(\fBstruct ifaddrs **\fR\fIifap\fR);
35 \fBvoid\fR \fBfreeifaddrs\fR(\fBstruct ifaddrs *\fR\fIifp\fR);
40 The \fBgetifaddrs\fR() function is used to obtain the list of network
41 interfaces on the local machine. A reference to a linked list of \fBifaddrs\fR
42 structures, as defined in \fB<ifaddrs.h>\fR, is stored in the memory referenced
43 by \fIifap\fR. Each structure in the list describes one network interface
44 address, and is of the form:
50 struct ifaddrs *ifa_next;
53 struct sockaddr *ifa_addr;
54 struct sockaddr *ifa_netmask;
56 struct sockaddr *ifu_broadaddr;
57 struct sockaddr *ifu_dstaddr;
61 #define ifa_broadaddr ifa_ifu.ifu_broadaddr
62 #define ifa_dstaddr ifa_ifu.ifu_dstaddr
68 The list is traversed by following the \fIifa_next\fR pointer. This member is
69 \fBNULL\fR on the last structure in the list.
73 The \fIifa_name\fR member contains the interface name.
77 The \fIifa_flags\fR member contains the interface flags.
81 The \fIifa_addr\fR member references the address of the interface. Use the
82 \fIsa_family\fR member of this structure to determine the format of the
83 address, as described in \fBsocket.h\fR(3HEAD).
87 The \fIifa_netmask\fR member references the netmask associated with ifa_addr,
88 or \fBNULL\fR if one is not set.
92 If the \fBIFF_BROADCAST\fR bit is set in \fIifa_flags\fR, then
93 \fIifa_broadaddr\fR is valid, or \fBNULL\fR if not present. If the
94 \fBIFF_POINTOPOINT\fR bit is set, then \fIifa_dstaddr\fR is valid, or \fBNULL\fR
95 if not present. These two flags are mutually exclusive; see \fBif_tcp\fR(7P)
100 The \fIifa_data\fR member is presently unused.
104 The memory used by \fBgetifaddrs\fR() to back the list is dynamically allocated.
105 It should be freed using \fBfreeifaddrs\fR().
109 If successful, \fBgetifaddrs\fR() returns the value \fB0\fR; otherwise it
110 returns \fB\(mi1\fR and sets \fIerrno\fR to indicate the error.
114 The \fBgetifaddrs\fR() function may fail and set \fIerrno\fR for any of the
115 errors specified for the library routines \fBioctl\fR(2),
116 \fBsocket\fR(3SOCKET), and \fBmalloc\fR(3C).
123 ATTRIBUTE TYPE ATTRIBUTE VALUE
125 Interface Stability Committed
132 \fBipadm\fR(1M), \fBifconfig\fR(1M), \fBioctl\fR(2), \fBmalloc\fR(3C),
133 \fBsocket\fR(3SOCKET), \fBsockaddr\fR(3SOCKET), \fBsocket.h\fR(3HEAD),
134 \fBif_tcp\fR(7P), \fBattributes\fR(5)
138 On an illumos system, this function lists only interfaces with the \fBIFF_UP\fR
139 flag set; see \fBif_tcp\fR(7P) and \fBifconfig\fR(1M) for more information.
143 At present, this function only lists addresses from the \fBAF_INET\fR and
144 \fBAF_INET6\fR families. Other families, such as \fBAF_LINK\fR, are not