backout: 3729 getifaddrs must learn to stop worrying and love the other address famil...
[unleashed.git] / usr / src / man / man3socket / getifaddrs.3socket
blob69324271affe0309ef0c5187cd5eb6747d641069
1 '\" t
2 .\"
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
6 .\" 1.0 of the CDDL.
7 .\"
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.
11 .\"
12 .\"
13 .\" Copyright (c) 2013, Joyent, Inc. All rights reserved.
14 .\"
15 .TH GETIFADDRS 3SOCKET "Apr 18, 2013"
16 .SH NAME
17 getifaddrs, freeifaddrs \- get interface addresses
18 .SH SYNOPSIS
19 .LP
20 .nf
21 \fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lsocket\fR \fB-lnsl\fR \
22 [ \fIlibrary\fR ... ]
23 #include <sys/types.h>
24 #include <sys/socket.h>
25 #include <ifaddrs.h>
26 .fi
28 .LP
29 .nf
30 \fBint\fR \fBgetifaddrs\fR(\fBstruct ifaddrs **\fR\fIifap\fR);
31 .fi
33 .LP
34 .nf
35 \fBvoid\fR \fBfreeifaddrs\fR(\fBstruct ifaddrs *\fR\fIifp\fR);
36 .fi
38 .SH DESCRIPTION
39 .LP
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:
46 .sp
47 .in +2
48 .nf
49 struct ifaddrs {
50     struct ifaddrs      *ifa_next;
51     char                *ifa_name;
52     uint64_t            ifa_flags;
53     struct sockaddr     *ifa_addr;
54     struct sockaddr     *ifa_netmask;
55     union {
56         struct sockaddr *ifu_broadaddr;
57         struct sockaddr *ifu_dstaddr;
58     } ifa_ifu;
59     void                *ifa_data;
61 #define ifa_broadaddr   ifa_ifu.ifu_broadaddr
62 #define ifa_dstaddr     ifa_ifu.ifu_dstaddr
63 .fi
64 .in -2
66 .sp
67 .LP
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.
71 .sp
72 .LP
73 The \fIifa_name\fR member contains the interface name.
75 .sp
76 .LP
77 The \fIifa_flags\fR member contains the interface flags.
79 .sp
80 .LP
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).
85 .sp
86 .LP
87 The \fIifa_netmask\fR member references the netmask associated with ifa_addr,
88 or \fBNULL\fR if one is not set.
90 .sp
91 .LP
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)
96 for more information.
98 .sp
99 .LP
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().
107 .SH RETURN VALUES
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.
112 .SH ERRORS
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).
118 .SH ATTRIBUTES
120 box;
121 c | c
122 l | l .
123 ATTRIBUTE TYPE  ATTRIBUTE VALUE
125 Interface Stability     Committed
127 MT-Level        MT-Safe
130 .SH SEE ALSO
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)
136 .SH NOTES
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.
141 .SH BUGS
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
145 included.