2 .\" Copyright (c) 2001, the Institute of Electrical and Electronics Engineers, Inc. and The Open Group. All Rights Reserved.
3 .\" Portions Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
4 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
6 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
7 .\" This notice shall appear on any product containing this material.
8 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
9 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
10 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
11 .TH FREEADDRINFO 3XNET "Feb 25, 2017"
13 freeaddrinfo, getaddrinfo \- get address information
17 \fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lxnet\fR [ \fIlibrary\fR ... ]
18 #include <sys/socket.h>
21 \fBvoid\fR \fBfreeaddrinfo\fR(\fBstruct addrinfo *\fR\fIai\fR);
26 \fBint\fR \fBgetaddrinfo\fR(\fBconst char *restrict\fR \fInodename\fR,
27 \fBconst char *restrict\fR \fIservname\fR, \fBconst struct addrinfo *restrict\fR \fIhints\fR,
28 \fBstruct addrinfo **restrict\fR \fIres\fR);
33 The \fBfreeaddrinfo()\fR function frees one or more \fBaddrinfo\fR structures
34 returned by \fBgetaddrinfo()\fR, along with any additional storage associated
35 with those structures. If the \fBai_next\fR member of the structure is not
36 null, the entire list of structures is freed. The \fBfreeaddrinfo()\fR function
37 supports the freeing of arbitrary sublists of an \fBaddrinfo\fR list originally
38 returned by \fBgetaddrinfo()\fR.
41 The \fBgetaddrinfo()\fR function translates the name of a service location (for
42 example, a host name) and/or a service name and returns a set of socket
43 addresses and associated information to be used in creating a socket with which
44 to address the specified service.
47 The \fInodename\fR and \fIservname\fR arguments are either null pointers or
48 pointers to null-terminated strings. One or both of these two arguments are
49 supplied by the application as a non-null pointer.
52 The format of a valid name depends on the address family or families. If a
53 specific family is not given and the name could be interpreted as valid within
54 multiple supported families, the implementation attempts to resolve the name in
55 all supported families and, in absence of errors, one or more results are
59 If the \fInodename\fR argument is not null, it can be a descriptive name or can
60 be an address string. If the specified address family is \fBAF_INET\fR,
61 \fBAF_INET6\fR, or \fBAF_UNSPEC\fR, valid descriptive names include host names.
62 If the specified address family is \fBAF_INET\fR or \fBAF_UNSPEC\fR, address
63 strings using Internet standard dot notation as specified in
64 \fBinet_addr\fR(3XNET) are valid.
67 If the specified address family is \fBAF_INET6\fR or \fBAF_UNSPEC\fR, standard
68 IPv6 text forms described in \fBinet_ntop\fR(3XNET) are valid.
71 If \fInodename\fR is not null, the requested service location is named by
72 \fInodename\fR; otherwise, the requested service location is local to the
76 If \fIservname\fR is null, the call returns network-level addresses for the
77 specified \fInodename\fR. If \fIservname\fR is not null, it is a
78 null-terminated character string identifying the requested service. This string
79 can be either a descriptive name or a numeric representation suitable for use
80 with the address family or families. If the specified address family is
81 \fBAF_INET\fR, \fBAF_INET6\fR, or \fBAF_UNSPEC\fR, the service can be specified
82 as a string specifying a decimal port number.
85 If the \fIhints\fR argument is not null, it refers to a structure containing
86 input values that can direct the operation by providing options and by limiting
87 the returned information to a specific socket type, address family and/or
88 protocol. In this \fIhints\fR structure every member other than \fBai_flags\fR,
89 \fBai_family\fR , \fBai_socktype\fR, and \fBai_protocol\fR is set to 0 or a
90 null pointer. A value of \fBAF_UNSPEC\fR for \fBai_family\fR means that the
91 caller accepts any address family. A value of 0 for \fBai_socktype\fR means
92 that the caller accepts any socket type. A value of 0 for \fBai_protocol\fR
93 means that the caller accepts any protocol. If \fIhints\fR is a null pointer,
94 the behavior is as if it referred to a structure containing the value 0 for the
95 \fBai_flags\fR, \fBai_socktype\fR, and \fBai_protocol\fR members, and
96 \fBAF_UNSPEC\fR for the \fBai_family\fR member.
99 The \fBai_flags\fR member to which the \fIhints\fR parameter points is set to 0
100 or be the bitwise-inclusive OR of one or more of the values \fBAI_PASSIVE\fR,
101 \fBAI_CANONNAME\fR, \fBAI_NUMERICHOST\fR, and \fBAI_NUMERICSERV\fR.
104 If the \fBAI_PASSIVE\fR flag is specified, the returned address information is
105 suitable for use in binding a socket for accepting incoming connections for the
106 specified service. In this case, if the \fInodename\fR argument is null, then
107 the IP address portion of the socket address structure is set to
108 \fBINADDR_ANY\fR for an IPv4 address or \fBIN6ADDR_ANY_INIT\fR for an IPv6
109 address. If the \fBAI_PASSIVE\fR flag is not specified, the returned address
110 information is suitable for a call to \fBconnect\fR(3XNET) (for a
111 connection-mode protocol) or for a call to \fBconnect()\fR,
112 \fBsendto\fR(3XNET), or \fBsendmsg\fR(3XNET) (for a connectionless protocol).
113 In this case, if the \fInodename\fR argument is null, then the IP address
114 portion of the socket address structure is set to the loopback address.
117 If the \fBAI_CANONNAME\fR flag is specified and the \fInodename\fR argument is
118 not null, the function attempts to determine the canonical name corresponding
119 to \fInodename\fR (for example, if \fInodename\fR is an alias or shorthand
120 notation for a complete name).
123 If the \fBAI_NUMERICHOST\fR flag is specified, then a non-null \fInodename\fR
124 string supplied is a numeric host address string. Otherwise, an
125 \fBEAI_NONAME\fR error is returned. This flag prevents any type of name
126 resolution service (for example, the DNS) from being invoked.
129 If the \fBAI_NUMERICSERV\fR flag is specified, then a non-null \fIservname\fR
130 string supplied is a numeric port string. Otherwise, an \fBEAI_NONAME\fR error
131 is returned. This flag prevents any type of name resolution service from being
135 If the \fBAI_V4MAPPED\fR flag is specified along with an \fBai_family\fR of
136 \fBAF_INET6\fR, then \fBgetaddrinfo()\fR returns IPv4-mapped IPv6 addresses on
137 finding no matching IPv6 addresses (\fBai_addrlen\fR is 16). The
138 \fBAI_V4MAPPED\fR flag is ignored unless \fBai_family\fR equals \fBAF_INET6\fR.
139 If the \fBAI_ALL\fR flag is used with the \fBAI_V4MAPPED\fR flag, then
140 \fBgetaddrinfo()\fR returns all matching IPv6 and IPv4 addresses. The
141 \fBAI_ALL\fR flag without the \fBAI_V4MAPPED\fR flag is ignored.
144 The \fBai_socktype\fR member to which argument hints points specifies the
145 socket type for the service, as defined in \fBsocket\fR(3XNET). If a specific
146 socket type is not given (for example, a value of 0) and the service name could
147 be interpreted as valid with multiple supported socket types, the
148 implementation attempts to resolve the service name for all supported socket
149 types and, in the absence of errors, all possible results are returned. A
150 non-zero socket type value limits the returned information to values with the
151 specified socket type.
154 If the \fBai_family\fR member to which hints points has the value
155 \fBAF_UNSPEC\fR, addresses are returned for use with any address family that
156 can be used with the specified \fInodename\fR and/or \fIservname\fR. Otherwise,
157 addresses are returned for use only with the specified address family. If
158 \fBai_family\fR is not \fBAF_UNSPEC\fR and \fBai_protocol\fR is not 0, then
159 addresses are returned for use only with the specified address family and
160 protocol; the value of \fBai_protocol\fR is interpreted as in a call to the
161 \fBsocket()\fR function with the corresponding values of \fBai_family\fR and
165 A 0 return value for \fBgetaddrinfo()\fR indicates successful completion; a
166 non-zero return value indicates failure. The possible values for the failures
167 are listed in the ERRORS section.
170 Upon successful return of \fBgetaddrinfo()\fR, the location to which res points
171 refers to a linked list of \fBaddrinfo\fR structures, each of which specifies a
172 socket address and information for use in creating a socket with which to use
173 that socket address. The list includes at least one \fBaddrinfo\fR structure.
174 The \fBai_next\fR member of each structure contains a pointer to the next
175 structure on the list, or a null pointer if it is the last structure on the
176 list. Each structure on the list includes values for use with a call to the
177 socket function, and a socket address for use with the connect function or, if
178 the \fBAI_PASSIVE\fR flag was specified, for use with the \fBbind\fR(3XNET)
179 function. The \fBai_family\fR , \fBai_socktype\fR, and \fBai_protocol\fR
180 members are usable as the arguments to the \fBsocket()\fR function to create a
181 socket suitable for use with the returned address. The \fBai_addr\fR and
182 \fBai_addrlen\fR members are usable as the arguments to the \fBconnect()\fR or
183 \fBbind()\fR functions with such a socket, according to the \fBAI_PASSIVE\fR
187 If \fInodename\fR is not null, and if requested by the \fBAI_CANONNAME\fR flag,
188 the \fBai_canonname\fR member of the first returned \fBaddrinfo\fR structure
189 points to a null-terminated string containing the canonical name corresponding
190 to the input \fInodename\fR. If the canonical name is not available, then
191 \fBai_canonname\fR refers to the \fInodename\fR argument or a string with the
192 same contents. The contents of the \fBai_flags\fR member of the returned
193 structures are undefined.
196 All members in socket address structures returned by \fBgetaddrinfo()\fR that
197 are not filled in through an explicit argument (for example,
198 \fBsin6_flowinfo\fR) are set to 0, making it easier to compare socket address
202 The \fBgetaddrinfo()\fR function will fail if:
206 \fB\fBEAI_AGAIN\fR\fR
209 The name could not be resolved at this time. Future attempts might succeed.
215 \fB\fBEAI_BADFLAGS\fR\fR
218 The \fBai_flags\fR member of the \fBaddrinfo\fR structure had an invalid value.
227 A non-recoverable error occurred when attempting to resolve the name.
233 \fB\fBEAI_FAMILY\fR\fR
236 The address family was not recognized.
242 \fB\fBEAI_MEMORY\fR\fR
245 There was a memory allocation failure when trying to allocate storage for the
252 \fB\fBEAI_NONAME\fR\fR
255 he name does not resolve for the supplied parameters. Neither \fInodename\fR
256 nor \fIservname\fR were supplied. At least one of these must be supplied.
262 \fB\fBEAI_SERVICE\fR\fR
265 The service passed was not recognized for the specified socket type.
271 \fB\fBEAI_SOCKTYPE\fR\fR
274 The intended socket type was not recognized.
280 \fB\fBEAI_SYSTEM\fR\fR
283 A system error occurred. The error code can be found in \fBerrno\fR.
289 \fB\fBEAI_OVERFLOW\fR\fR
292 An argument buffer overflowed.
297 If the caller handles only TCP and not UDP, for example, then the
298 \fBai_protocol\fR member of the \fIhints\fR structure should be set to
299 \fBIPPROTO_TCP\fR when \fBgetaddrinfo()\fR is called.
302 If the caller handles only IPv4 and not IPv6, then the \fBai_family\fR member
303 of the \fIhints\fR structure should be set to \fBAF_INET\fR when
304 \fBgetaddrinfo()\fR is called.
307 See \fBattributes\fR(5) for descriptions of the following attributes:
315 ATTRIBUTE TYPE ATTRIBUTE VALUE
317 Interface Stability Standard
324 \fBconnect\fR(3XNET), \fBgai_strerror\fR(3XNET), \fBgethostbyname\fR(3XNET),
325 \fBgetnameinfo\fR(3XNET), \fBgetservbyname\fR(3XNET), \fBinet_addr\fR(3XNET),
326 \fBinet_ntop\fR(3XNET), \fBsocket\fR(3XNET), \fBattributes\fR(5),