Change the upstream source URL
[platform/upstream/c-ares.git] / docs / ares_init_options.3
1 .\"
2 .\" Copyright 1998 by the Massachusetts Institute of Technology.
3 .\" Copyright (C) 2004-2010 by Daniel Stenberg
4 .\"
5 .\" Permission to use, copy, modify, and distribute this
6 .\" software and its documentation for any purpose and without
7 .\" fee is hereby granted, provided that the above copyright
8 .\" notice appear in all copies and that both that copyright
9 .\" notice and this permission notice appear in supporting
10 .\" documentation, and that the name of M.I.T. not be used in
11 .\" advertising or publicity pertaining to distribution of the
12 .\" software without specific, written prior permission.
13 .\" M.I.T. makes no representations about the suitability of
14 .\" this software for any purpose.  It is provided "as is"
15 .\" without express or implied warranty.
16 .\"
17 .TH ARES_INIT 3 "5 March 2010"
18 .SH NAME
19 ares_init_options \- Initialize a resolver channel
20 .SH SYNOPSIS
21 .nf
22 #include <ares.h>
23
24 struct ares_options {
25   int flags;
26   int timeout; /* in seconds or milliseconds, depending on options */
27   int tries;
28   int ndots;
29   unsigned short udp_port;
30   unsigned short tcp_port;
31   int socket_send_buffer_size;
32   int socket_receive_buffer_size;
33   struct in_addr *servers;
34   int nservers;
35   char **domains;
36   int ndomains;
37   char *lookups;
38   ares_sock_state_cb sock_state_cb;
39   void *sock_state_cb_data;
40   struct apattern *sortlist;
41   int nsort;
42   int ednspsz;
43   char *resolvconf_path;
44 };
45
46 int ares_init_options(ares_channel *\fIchannelptr\fP,
47                       struct ares_options *\fIoptions\fP,
48                       int \fIoptmask\fP)
49 .fi
50 .SH DESCRIPTION
51 The \fBares_init_options(3)\fP function initializes a communications channel
52 for name service lookups.  If it returns successfully,
53 \fBares_init_options(3)\fP will set the variable pointed to by
54 \fIchannelptr\fP to a handle used to identify the name service channel.  The
55 caller should invoke \fIares_destroy(3)\fP on the handle when the channel is
56 no longer needed.
57
58 The \fIoptmask\fP parameter generally specifies which fields in the structure pointed to
59 by \fIoptions\fP are set, as follows:
60 .TP 18
61 .B ARES_OPT_FLAGS
62 .B int \fIflags\fP;
63 .br
64 Flags controlling the behavior of the resolver.  See below for a
65 description of possible flag values.
66 .TP 18
67 .B ARES_OPT_TIMEOUT
68 .B int \fItimeout\fP;
69 .br
70 The number of seconds each name server is given to respond to a query on the
71 first try.  (After the first try, the timeout algorithm becomes more
72 complicated, but scales linearly with the value of \fItimeout\fP.)  The
73 default is five seconds. This option is being deprecated by
74 \fIARES_OPT_TIMEOUTMS\fP starting in c-ares 1.5.2.
75 .TP 18
76 .B ARES_OPT_TIMEOUTMS
77 .B int \fItimeout\fP;
78 .br
79 The number of milliseconds each name server is given to respond to a query on
80 the first try.  (After the first try, the timeout algorithm becomes more
81 complicated, but scales linearly with the value of \fItimeout\fP.)  The
82 default is five seconds. Note that this option is specified with the same
83 struct field as the former \fIARES_OPT_TIMEOUT\fP, it is but the option bits
84 that tell c-ares how to interpret the number. This option was added in c-ares
85 1.5.2.
86 .TP 18
87 .B ARES_OPT_TRIES
88 .B int \fItries\fP;
89 .br
90 The number of tries the resolver will try contacting each name server
91 before giving up.  The default is four tries.
92 .TP 18
93 .B ARES_OPT_NDOTS
94 .B int \fIndots\fP;
95 .br
96 The number of dots which must be present in a domain name for it to be
97 queried for "as is" prior to querying for it with the default domain
98 extensions appended.  The default value is 1 unless set otherwise by
99 resolv.conf or the RES_OPTIONS environment variable.
100 .TP 18
101 .B ARES_OPT_UDP_PORT
102 .B unsigned short \fIudp_port\fP;
103 .br
104 The port to use for queries over UDP, in network byte order.
105 The default value is 53 (in network byte order), the standard name
106 service port.
107 .TP 18
108 .B ARES_OPT_TCP_PORT
109 .B unsigned short \fItcp_port\fP;
110 .br
111 The port to use for queries over TCP, in network byte order.
112 The default value is 53 (in network byte order), the standard name
113 service port.
114 .TP 18
115 .B ARES_OPT_SERVERS
116 .B struct in_addr *\fIservers\fP;
117 .br
118 .B int \fInservers\fP;
119 .br
120 The list of IPv4 servers to contact, instead of the servers specified in
121 resolv.conf or the local named. In order to allow specification of either
122 IPv4 or IPv6 name servers, the
123 .BR ares_set_servers(3)
124 function must be used instead.
125 .TP 18
126 .B ARES_OPT_DOMAINS
127 .B char **\fIdomains\fP;
128 .br
129 .B int \fIndomains\fP;
130 .br
131 The domains to search, instead of the domains specified in resolv.conf
132 or the domain derived from the kernel hostname variable.
133 .TP 18
134 .B ARES_OPT_LOOKUPS
135 .B char *\fIlookups\fP;
136 .br
137 The lookups to perform for host queries.
138 .I lookups
139 should be set to a string of the characters "b" or "f", where "b"
140 indicates a DNS lookup and "f" indicates a lookup in the hosts file.
141 .TP 18
142 .B ARES_OPT_SOCK_STATE_CB
143 .B void (*\fIsock_state_cb\fP)(void *data, ares_socket_t socket_fd, int readable, int writable);
144 .br
145 .B void *\fIsock_state_cb_data\fP;
146 .br
147 A callback function to be invoked when a socket changes state.
148 .I socket_fd
149 will be passed the socket whose state has changed;
150 .I readable
151 will be set to true if the socket should listen for read events, and
152 .I writable
153 will be set to true if the socket should listen for write events.
154 The value of
155 .I sock_state_cb_data
156 will be passed as the
157 .I data
158 argument.
159 .TP 18
160 .B ARES_OPT_SORTLIST
161 .B struct apattern *\fIsortlist\fP;
162 .br
163 .B int \fInsort\fP;
164 .br
165 A list of IP address ranges that specifies the order of preference that
166 results from \fIares_gethostbyname\fP should be returned in.  Note that
167 this can only be used with a sortlist retrieved via
168 \fBares_save_options(3)\fP (because
169 .B struct apattern
170 is opaque); to set a fresh sort list, use \fBares_set_sortlist(3)\fP.
171 .TP 18
172 .B ARES_OPT_SOCK_SNDBUF
173 .B int \fIsocket_send_buffer_size\fP;
174 .br
175 The send buffer size to set for the socket.
176 .TP 18
177 .B ARES_OPT_SOCK_RCVBUF
178 .B int \fIsocket_receive_buffer_size\fP;
179 .br
180 The receive buffer size to set for the socket.
181 .TP 18
182 .B ARES_OPT_EDNSPSZ
183 .B int \fIednspsz\fP;
184 .br
185 The message size to be advertized in EDNS; only takes effect if the
186 .B ARES_FLAG_EDNS
187 flag is set.
188 .TP 18
189 .B ARES_OPT_RESOLVCONF
190 .B char *\fIresolvconf_path\fP;
191 .br
192 The path to use for reading the resolv.conf file. The
193 .I resolvconf_path
194 should be set to a path string, and will be honoured on *nix like systems. The
195 default is
196 .B /etc/resolv.conf
197 .br
198 .PP
199 The \fIoptmask\fP parameter also includes options without a corresponding
200 field in the
201 .B ares_options
202 structure, as follows:
203 .TP 23
204 .B ARES_OPT_ROTATE
205 Perform round-robin selection of the nameservers configured for the channel
206 for each resolution.
207 .TP 23
208 .B ARES_OPT_NOROTATE
209 Do not perform round-robin nameserver selection; always use the list of
210 nameservers in the same order.
211 .PP
212 The
213 .I flags
214 field should be the bitwise or of some subset of the following values:
215 .TP 23
216 .B ARES_FLAG_USEVC
217 Always use TCP queries (the "virtual circuit") instead of UDP
218 queries.  Normally, TCP is only used if a UDP query yields a truncated
219 result.
220 .TP 23
221 .B ARES_FLAG_PRIMARY
222 Only query the first server in the list of servers to query.
223 .TP 23
224 .B ARES_FLAG_IGNTC
225 If a truncated response to a UDP query is received, do not fall back
226 to TCP; simply continue on with the truncated response.
227 .TP 23
228 .B ARES_FLAG_NORECURSE
229 Do not set the "recursion desired" bit on outgoing queries, so that the name
230 server being contacted will not try to fetch the answer from other servers if
231 it doesn't know the answer locally. Be aware that ares will not do the
232 recursion for you.  Recursion must be handled by the application calling ares
233 if \fIARES_FLAG_NORECURSE\fP is set.
234 .TP 23
235 .B ARES_FLAG_STAYOPEN
236 Do not close communications sockets when the number of active queries
237 drops to zero.
238 .TP 23
239 .B ARES_FLAG_NOSEARCH
240 Do not use the default search domains; only query hostnames as-is or
241 as aliases.
242 .TP 23
243 .B ARES_FLAG_NOALIASES
244 Do not honor the HOSTALIASES environment variable, which normally
245 specifies a file of hostname translations.
246 .TP 23
247 .B ARES_FLAG_NOCHECKRESP
248 Do not discard responses with the SERVFAIL, NOTIMP, or REFUSED
249 response code or responses whose questions don't match the questions
250 in the request.  Primarily useful for writing clients which might be
251 used to test or debug name servers.
252 .TP 23
253 .B ARES_FLAG_EDNS
254 Include an EDNS pseudo-resource record (RFC 2671) in generated requests.
255 .SH RETURN VALUES
256 \fBares_init_options(3)\fP can return any of the following values:
257 .TP 14
258 .B ARES_SUCCESS
259 Initialization succeeded.
260 .TP 14
261 .B ARES_EFILE
262 A configuration file could not be read.
263 .TP 14
264 .B ARES_ENOMEM
265 The process's available memory was exhausted.
266 .TP 14
267 .B ARES_ENOTINITIALIZED
268 c-ares library initialization not yet performed.
269 .SH NOTES
270 When initializing from
271 .B /etc/resolv.conf,
272 (or, alternatively when specified by the
273 .I resolvconf_path
274 path location)
275 \fBares_init_options(3)\fP reads the \fIdomain\fP and \fIsearch\fP directives
276 to allow lookups of short names relative to the domains specified. The
277 \fIdomain\fP and \fIsearch\fP directives override one another. If more that
278 one instance of either \fIdomain\fP or \fIsearch\fP directives is specified,
279 the last occurrence wins. For more information, please see the
280 .BR resolv.conf (5)
281 manual page.
282 .SH SEE ALSO
283 .BR ares_init(3),
284 .BR ares_destroy(3),
285 .BR ares_dup(3),
286 .BR ares_library_init(3),
287 .BR ares_save_options(3),
288 .BR ares_set_servers(3),
289 .BR ares_set_sortlist(3)
290 .SH AUTHOR
291 Greg Hudson, MIT Information Systems
292 .br
293 Copyright 1998 by the Massachusetts Institute of Technology.
294 .br
295 Copyright (C) 2004-2010 by Daniel Stenberg.