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 "May 18, 2017"
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 specific to the address family. It is currently
101 only available for AF_LINK entries where it contains a pointer to the
102 \fBstruct if_data\fR (as defined in \fBif.h\fR(3HEAD)).
106 The memory used by \fBgetifaddrs\fR() to back the list is dynamically allocated.
107 It should be freed using \fBfreeifaddrs\fR().
111 If successful, \fBgetifaddrs\fR() returns the value \fB0\fR; otherwise it
112 returns \fB\(mi1\fR and sets \fIerrno\fR to indicate the error.
116 The \fBgetifaddrs\fR() function may fail and set \fIerrno\fR for any of the
117 errors specified for the library routines \fBioctl\fR(2),
118 \fBsocket\fR(3SOCKET), and \fBmalloc\fR(3C).
125 ATTRIBUTE TYPE ATTRIBUTE VALUE
127 Interface Stability Committed
134 \fBipadm\fR(1M), \fBifconfig\fR(1M), \fBioctl\fR(2), \fBmalloc\fR(3C),
135 \fBsocket\fR(3SOCKET), \fBsockaddr\fR(3SOCKET), \fBsocket.h\fR(3HEAD),
136 \fBif_tcp\fR(7P), \fBattributes\fR(5)
140 This function lists interfaces of type AF_INET, AF_INET6, and AF_LINK.
141 For AF_INET and AF_INET6 only interfaces with the \fBIFF_UP\fR
142 flag set are listed; see \fBif_tcp\fR(7P) and \fBifconfig\fR(1M) for more
143 information. For AF_LINK entries the interface index is only available when the