2 .\" Copyright 1998 by the Massachusetts Institute of Technology.
3 .\" Copyright (C) 2004-2010 by Daniel Stenberg
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.
17 .TH ARES_INIT 3 "5 March 2010"
19 ares_init_options \- Initialize a resolver channel
26 int timeout; /* in seconds or milliseconds, depending on options */
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;
38 ares_sock_state_cb sock_state_cb;
39 void *sock_state_cb_data;
40 struct apattern *sortlist;
43 char *resolvconf_path;
46 int ares_init_options(ares_channel *\fIchannelptr\fP,
47 struct ares_options *\fIoptions\fP,
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
58 The \fIoptmask\fP parameter generally specifies which fields in the structure pointed to
59 by \fIoptions\fP are set, as follows:
64 Flags controlling the behavior of the resolver. See below for a
65 description of possible flag values.
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.
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
90 The number of tries the resolver will try contacting each name server
91 before giving up. The default is four tries.
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.
102 .B unsigned short \fIudp_port\fP;
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
109 .B unsigned short \fItcp_port\fP;
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
116 .B struct in_addr *\fIservers\fP;
118 .B int \fInservers\fP;
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.
127 .B char **\fIdomains\fP;
129 .B int \fIndomains\fP;
131 The domains to search, instead of the domains specified in resolv.conf
132 or the domain derived from the kernel hostname variable.
135 .B char *\fIlookups\fP;
137 The lookups to perform for host queries.
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.
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);
145 .B void *\fIsock_state_cb_data\fP;
147 A callback function to be invoked when a socket changes state.
149 will be passed the socket whose state has changed;
151 will be set to true if the socket should listen for read events, and
153 will be set to true if the socket should listen for write events.
155 .I sock_state_cb_data
156 will be passed as the
161 .B struct apattern *\fIsortlist\fP;
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
170 is opaque); to set a fresh sort list, use \fBares_set_sortlist(3)\fP.
172 .B ARES_OPT_SOCK_SNDBUF
173 .B int \fIsocket_send_buffer_size\fP;
175 The send buffer size to set for the socket.
177 .B ARES_OPT_SOCK_RCVBUF
178 .B int \fIsocket_receive_buffer_size\fP;
180 The receive buffer size to set for the socket.
183 .B int \fIednspsz\fP;
185 The message size to be advertized in EDNS; only takes effect if the
189 .B ARES_OPT_RESOLVCONF
190 .B char *\fIresolvconf_path\fP;
192 The path to use for reading the resolv.conf file. The
194 should be set to a path string, and will be honoured on *nix like systems. The
199 The \fIoptmask\fP parameter also includes options without a corresponding
202 structure, as follows:
205 Perform round-robin selection of the nameservers configured for the channel
209 Do not perform round-robin nameserver selection; always use the list of
210 nameservers in the same order.
214 field should be the bitwise or of some subset of the following values:
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
222 Only query the first server in the list of servers to query.
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.
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.
235 .B ARES_FLAG_STAYOPEN
236 Do not close communications sockets when the number of active queries
239 .B ARES_FLAG_NOSEARCH
240 Do not use the default search domains; only query hostnames as-is or
243 .B ARES_FLAG_NOALIASES
244 Do not honor the HOSTALIASES environment variable, which normally
245 specifies a file of hostname translations.
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.
254 Include an EDNS pseudo-resource record (RFC 2671) in generated requests.
256 \fBares_init_options(3)\fP can return any of the following values:
259 Initialization succeeded.
262 A configuration file could not be read.
265 The process's available memory was exhausted.
267 .B ARES_ENOTINITIALIZED
268 c-ares library initialization not yet performed.
270 When initializing from
272 (or, alternatively when specified by the
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
286 .BR ares_library_init(3),
287 .BR ares_save_options(3),
288 .BR ares_set_servers(3),
289 .BR ares_set_sortlist(3)
291 Greg Hudson, MIT Information Systems
293 Copyright 1998 by the Massachusetts Institute of Technology.
295 Copyright (C) 2004-2010 by Daniel Stenberg.