Merge branch 'vendor/LIBPCAP' (early part)
[dragonfly.git] / contrib / bind-9.3 / lib / lwres / man / lwres_getaddrinfo.3
1 .\" Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
2 .\" Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
3 .\" 
4 .\" Permission to use, copy, modify, and distribute this software for any
5 .\" purpose with or without fee is hereby granted, provided that the above
6 .\" copyright notice and this permission notice appear in all copies.
7 .\" 
8 .\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 .\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 .\" AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 .\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 .\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 .\" PERFORMANCE OF THIS SOFTWARE.
15 .\"
16 .\" $Id: lwres_getaddrinfo.3,v 1.16.2.1.8.7 2006/06/29 13:02:31 marka Exp $
17 .\"
18 .hy 0
19 .ad l
20 .\"     Title: lwres_getaddrinfo
21 .\"    Author: 
22 .\" Generator: DocBook XSL Stylesheets v1.70.1 <http://docbook.sf.net/>
23 .\"      Date: Jun 30, 2000
24 .\"    Manual: BIND9
25 .\"    Source: BIND9
26 .\"
27 .TH "LWRES_GETADDRINFO" "3" "Jun 30, 2000" "BIND9" "BIND9"
28 .\" disable hyphenation
29 .nh
30 .\" disable justification (adjust text to left margin only)
31 .ad l
32 .SH "NAME"
33 lwres_getaddrinfo, lwres_freeaddrinfo \- socket address structure to host and service name
34 .SH "SYNOPSIS"
35 .nf
36 #include <lwres/netdb.h>
37 .fi
38 .HP 22
39 .BI "int lwres_getaddrinfo(const\ char\ *hostname, const\ char\ *servname, const\ struct\ addrinfo\ *hints, struct\ addrinfo\ **res);"
40 .HP 24
41 .BI "void lwres_freeaddrinfo(struct\ addrinfo\ *ai);"
42 .PP
43 If the operating system does not provide a
44 \fBstruct addrinfo\fR, the following structure is used:
45 .sp
46 .RS 3n
47 .nf
48 struct  addrinfo {
49         int             ai_flags;       /* AI_PASSIVE, AI_CANONNAME */
50         int             ai_family;      /* PF_xxx */
51         int             ai_socktype;    /* SOCK_xxx */
52         int             ai_protocol;    /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
53         size_t          ai_addrlen;     /* length of ai_addr */
54         char            *ai_canonname;  /* canonical name for hostname */
55         struct sockaddr *ai_addr;       /* binary address */
56         struct addrinfo *ai_next;       /* next structure in linked list */
57 };
58 .fi
59 .RE
60 .sp
61 .SH "DESCRIPTION"
62 .PP
63 \fBlwres_getaddrinfo()\fR
64 is used to get a list of IP addresses and port numbers for host
65 \fIhostname\fR
66 and service
67 \fIservname\fR. The function is the lightweight resolver's implementation of
68 \fBgetaddrinfo()\fR
69 as defined in RFC2133.
70 \fIhostname\fR
71 and
72 \fIservname\fR
73 are pointers to null\-terminated strings or
74 \fBNULL\fR.
75 \fIhostname\fR
76 is either a host name or a numeric host address string: a dotted decimal IPv4 address or an IPv6 address.
77 \fIservname\fR
78 is either a decimal port number or a service name as listed in
79 \fI/etc/services\fR.
80 .PP
81 \fIhints\fR
82 is an optional pointer to a
83 \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
84 \fI*hints\fR:
85 .TP 3n
86 \fBai_family\fR
87 The protocol family that should be used. When
88 \fBai_family\fR
89 is set to
90 \fBPF_UNSPEC\fR, it means the caller will accept any protocol family supported by the operating system.
91 .TP 3n
92 \fBai_socktype\fR
93 denotes the type of socket \(em
94 \fBSOCK_STREAM\fR,
95 \fBSOCK_DGRAM\fR
96 or
97 \fBSOCK_RAW\fR
98 \(em that is wanted. When
99 \fBai_socktype\fR
100 is zero the caller will accept any socket type.
101 .TP 3n
102 \fBai_protocol\fR
103 indicates which transport protocol is wanted: IPPROTO_UDP or IPPROTO_TCP. If
104 \fBai_protocol\fR
105 is zero the caller will accept any protocol.
106 .TP 3n
107 \fBai_flags\fR
108 Flag bits. If the
109 \fBAI_CANONNAME\fR
110 bit is set, a successful call to
111 \fBlwres_getaddrinfo()\fR
112 will return a null\-terminated string containing the canonical name of the specified hostname in
113 \fBai_canonname\fR
114 of the first
115 \fBaddrinfo\fR
116 structure returned. Setting the
117 \fBAI_PASSIVE\fR
118 bit indicates that the returned socket address structure is intended for used in a call to
119 \fBbind\fR(2). In this case, if the hostname argument is a
120 \fBNULL\fR
121 pointer, then the IP address portion of the socket address structure will be set to
122 \fBINADDR_ANY\fR
123 for an IPv4 address or
124 \fBIN6ADDR_ANY_INIT\fR
125 for an IPv6 address.
126 .sp
127 When
128 \fBai_flags\fR
129 does not set the
130 \fBAI_PASSIVE\fR
131 bit, the returned socket address structure will be ready for use in a call to
132 \fBconnect\fR(2 )
133 for a connection\-oriented protocol or
134 \fBconnect\fR(2),
135 \fBsendto\fR(2), or
136 \fBsendmsg\fR(2 )
137 if a connectionless protocol was chosen. The IP address portion of the socket address structure will be set to the loopback address if
138 \fIhostname\fR
139 is a
140 \fBNULL\fR
141 pointer and
142 \fBAI_PASSIVE\fR
143 is not set in
144 \fBai_flags\fR.
145 .sp
146 If
147 \fBai_flags\fR
148 is set to
149 \fBAI_NUMERICHOST\fR
150 it indicates that
151 \fIhostname\fR
152 should be treated as a numeric string defining an IPv4 or IPv6 address and no name resolution should be attempted.
153 .PP
154 All other elements of the
155 \fBstruct addrinfo\fR
156 passed via
157 \fIhints\fR
158 must be zero.
159 .PP
160 A
161 \fIhints\fR
162 of
163 \fBNULL\fR
164 is treated as if the caller provided a
165 \fBstruct addrinfo\fR
166 initialized to zero with
167 \fBai_family\fRset to
168 \fBPF_UNSPEC\fR.
169 .PP
170 After a successful call to
171 \fBlwres_getaddrinfo()\fR,
172 \fI*res\fR
173 is a pointer to a linked list of one or more
174 \fBaddrinfo\fR
175 structures. Each
176 \fBstruct addrinfo\fR
177 in this list cn be processed by following the
178 \fBai_next\fR
179 pointer, until a
180 \fBNULL\fR
181 pointer is encountered. The three members
182 \fBai_family\fR,
183 \fBai_socktype\fR, and
184 \fBai_protocol\fR
185 in each returned
186 \fBaddrinfo\fR
187 structure contain the corresponding arguments for a call to
188 \fBsocket\fR(2). For each
189 \fBaddrinfo\fR
190 structure in the list, the
191 \fBai_addr\fR
192 member points to a filled\-in socket address structure of length
193 \fBai_addrlen\fR.
194 .PP
195 All of the information returned by
196 \fBlwres_getaddrinfo()\fR
197 is dynamically allocated: the addrinfo structures, and the socket address structures and canonical host name strings pointed to by the
198 \fBaddrinfo\fRstructures. Memory allocated for the dynamically allocated structures created by a successful call to
199 \fBlwres_getaddrinfo()\fR
200 is released by
201 \fBlwres_freeaddrinfo()\fR.
202 \fIai\fR
203 is a pointer to a
204 \fBstruct addrinfo\fR
205 created by a call to
206 \fBlwres_getaddrinfo()\fR.
207 .SH "RETURN VALUES"
208 .PP
209 \fBlwres_getaddrinfo()\fR
210 returns zero on success or one of the error codes listed in
211 \fBgai_strerror\fR(3 )
212 if an error occurs. If both
213 \fIhostname\fR
214 and
215 \fIservname\fR
216 are
217 \fBNULL\fR
218 \fBlwres_getaddrinfo()\fR
219 returns
220 \fBEAI_NONAME\fR.
221 .SH "SEE ALSO"
222 .PP
223 \fBlwres\fR(3),
224 \fBlwres_getaddrinfo\fR(3),
225 \fBlwres_freeaddrinfo\fR(3),
226 \fBlwres_gai_strerror\fR(3),
227 \fBRFC2133\fR(),
228 \fBgetservbyname\fR(3),
229 \fBbind\fR(2),
230 \fBconnect\fR(2),
231 \fBsendto\fR(2),
232 \fBsendmsg\fR(2),
233 \fBsocket\fR(2).
234 .SH "COPYRIGHT"
235 Copyright \(co 2004, 2005 Internet Systems Consortium, Inc. ("ISC")