1 .\" $NetBSD: lwres_getaddrinfo.3,v 1.5 2014/12/10 04:38:02 christos Exp $
3 .\" Copyright (C) 2004, 2005, 2007, 2014 Internet Systems Consortium, Inc. ("ISC")
4 .\" Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
6 .\" Permission to use, copy, modify, and/or distribute this software for any
7 .\" purpose with or without fee is hereby granted, provided that the above
8 .\" copyright notice and this permission notice appear in all copies.
10 .\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 .\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 .\" AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 .\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 .\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 .\" PERFORMANCE OF THIS SOFTWARE.
22 .\" Title: lwres_getaddrinfo
24 .\" Generator: DocBook XSL Stylesheets v1.71.1 <http://docbook.sf.net/>
25 .\" Date: June 18, 2007
29 .TH "LWRES_GETADDRINFO" "3" "June 18, 2007" "BIND9" "BIND9"
30 .\" disable hyphenation
32 .\" disable justification (adjust text to left margin only)
35 lwres_getaddrinfo, lwres_freeaddrinfo \- socket address structure to host and service name
38 #include <lwres/netdb.h>
41 .BI "int lwres_getaddrinfo(const\ char\ *" "hostname" ", const\ char\ *" "servname" ", const\ struct\ addrinfo\ *" "hints" ", struct\ addrinfo\ **" "res" ");"
43 .BI "void lwres_freeaddrinfo(struct\ addrinfo\ *" "ai" ");"
45 If the operating system does not provide a
46 \fBstruct addrinfo\fR, the following structure is used:
51 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
52 int ai_family; /* PF_xxx */
53 int ai_socktype; /* SOCK_xxx */
54 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
55 size_t ai_addrlen; /* length of ai_addr */
56 char *ai_canonname; /* canonical name for hostname */
57 struct sockaddr *ai_addr; /* binary address */
58 struct addrinfo *ai_next; /* next structure in linked list */
65 \fBlwres_getaddrinfo()\fR
66 is used to get a list of IP addresses and port numbers for host
69 \fIservname\fR. The function is the lightweight resolver's implementation of
71 as defined in RFC2133.
75 are pointers to null\-terminated strings or
78 is either a host name or a numeric host address string: a dotted decimal IPv4 address or an IPv6 address.
80 is either a decimal port number or a service name as listed in
84 is an optional pointer to a
85 \fBstruct addrinfo\fR. This structure can be used to provide hints concerning the type of socket that the caller supports or wishes to use. The caller can supply the following structure elements in
90 The protocol family that should be used. When
93 \fBPF_UNSPEC\fR, it means the caller will accept any protocol family supported by the operating system.
98 denotes the type of socket \(em
103 \(em that is wanted. When
105 is zero the caller will accept any socket type.
110 indicates which transport protocol is wanted: IPPROTO_UDP or IPPROTO_TCP. If
112 is zero the caller will accept any protocol.
119 bit is set, a successful call to
120 \fBlwres_getaddrinfo()\fR
121 will return a null\-terminated string containing the canonical name of the specified hostname in
125 structure returned. Setting the
127 bit indicates that the returned socket address structure is intended for used in a call to
128 \fBbind\fR(2). In this case, if the hostname argument is a
130 pointer, then the IP address portion of the socket address structure will be set to
132 for an IPv4 address or
133 \fBIN6ADDR_ANY_INIT\fR
140 bit, the returned socket address structure will be ready for use in a call to
142 for a connection\-oriented protocol or
146 if a connectionless protocol was chosen. The IP address portion of the socket address structure will be set to the loopback address if
161 should be treated as a numeric string defining an IPv4 or IPv6 address and no name resolution should be attempted.
164 All other elements of the
165 \fBstruct addrinfo\fR
174 is treated as if the caller provided a
175 \fBstruct addrinfo\fR
176 initialized to zero with
177 \fBai_family\fRset to
180 After a successful call to
181 \fBlwres_getaddrinfo()\fR,
183 is a pointer to a linked list of one or more
186 \fBstruct addrinfo\fR
187 in this list cn be processed by following the
191 pointer is encountered. The three members
193 \fBai_socktype\fR, and
197 structure contain the corresponding arguments for a call to
198 \fBsocket\fR(2). For each
200 structure in the list, the
202 member points to a filled\-in socket address structure of length
205 All of the information returned by
206 \fBlwres_getaddrinfo()\fR
207 is dynamically allocated: the addrinfo structures, and the socket address structures and canonical host name strings pointed to by the
208 \fBaddrinfo\fRstructures. Memory allocated for the dynamically allocated structures created by a successful call to
209 \fBlwres_getaddrinfo()\fR
211 \fBlwres_freeaddrinfo()\fR.
214 \fBstruct addrinfo\fR
216 \fBlwres_getaddrinfo()\fR.
219 \fBlwres_getaddrinfo()\fR
220 returns zero on success or one of the error codes listed in
221 \fBgai_strerror\fR(3)
222 if an error occurs. If both
228 \fBlwres_getaddrinfo()\fR
234 \fBlwres_getaddrinfo\fR(3),
235 \fBlwres_freeaddrinfo\fR(3),
236 \fBlwres_gai_strerror\fR(3),
238 \fBgetservbyname\fR(3),
245 Copyright \(co 2004, 2005, 2007, 2014 Internet Systems Consortium, Inc. ("ISC")
247 Copyright \(co 2000, 2001, 2003 Internet Software Consortium.