1ARES_INIT(3) Library Functions Manual ARES_INIT(3)
2
3
4
6 ares_init_options - Initialize a resolver channel
7
9 #include <ares.h>
10
11 struct ares_options {
12 int flags;
13 int timeout; /* in seconds or milliseconds, depending on options */
14 int tries;
15 int ndots;
16 unsigned short udp_port;
17 unsigned short tcp_port;
18 int socket_send_buffer_size;
19 int socket_receive_buffer_size;
20 struct in_addr *servers;
21 int nservers;
22 char **domains;
23 int ndomains;
24 char *lookups;
25 ares_sock_state_cb sock_state_cb;
26 void *sock_state_cb_data;
27 struct apattern *sortlist;
28 int nsort;
29 int ednspsz;
30 };
31
32 int ares_init_options(ares_channel *channelptr,
33 struct ares_options *options,
34 int optmask)
35
37 The ares_init_options(3) function initializes a communications channel
38 for name service lookups. If it returns successfully,
39 ares_init_options(3) will set the variable pointed to by channelptr to
40 a handle used to identify the name service channel. The caller should
41 invoke ares_destroy(3) on the handle when the channel is no longer
42 needed.
43
44 The optmask parameter generally specifies which fields in the structure
45 pointed to by options are set, as follows:
46
47 ARES_OPT_FLAGS int flags;
48 Flags controlling the behavior of the resolver. See
49 below for a description of possible flag values.
50
51 ARES_OPT_TIMEOUT int timeout;
52 The number of seconds each name server is given to
53 respond to a query on the first try. (After the
54 first try, the timeout algorithm becomes more compli‐
55 cated, but scales linearly with the value of time‐
56 out.) The default is five seconds. This option is
57 being deprecated by ARES_OPT_TIMEOUTMS starting in c-
58 ares 1.5.2.
59
60 ARES_OPT_TIMEOUTMS
61 int timeout;
62 The number of milliseconds each name server is given
63 to respond to a query on the first try. (After the
64 first try, the timeout algorithm becomes more compli‐
65 cated, but scales linearly with the value of time‐
66 out.) The default is five seconds. Note that this
67 option is specified with the same struct field as the
68 former ARES_OPT_TIMEOUT, it is but the option bits
69 that tell c-ares how to interpret the number. This
70 option was added in c-ares 1.5.2.
71
72 ARES_OPT_TRIES int tries;
73 The number of tries the resolver will try contacting
74 each name server before giving up. The default is
75 four tries.
76
77 ARES_OPT_NDOTS int ndots;
78 The number of dots which must be present in a domain
79 name for it to be queried for "as is" prior to query‐
80 ing for it with the default domain extensions
81 appended. The default value is 1 unless set other‐
82 wise by resolv.conf or the RES_OPTIONS environment
83 variable.
84
85 ARES_OPT_UDP_PORT unsigned short udp_port;
86 The port to use for queries over UDP, in network byte
87 order. The default value is 53 (in network byte
88 order), the standard name service port.
89
90 ARES_OPT_TCP_PORT unsigned short tcp_port;
91 The port to use for queries over TCP, in network byte
92 order. The default value is 53 (in network byte
93 order), the standard name service port.
94
95 ARES_OPT_SERVERS struct in_addr *servers;
96 int nservers;
97 The list of IPv4 servers to contact, instead of the
98 servers specified in resolv.conf or the local named.
99 In order to allow specification of either IPv4 or
100 IPv6 name servers, the ares_set_servers(3) function
101 must be used instead.
102
103 ARES_OPT_DOMAINS char **domains;
104 int ndomains;
105 The domains to search, instead of the domains speci‐
106 fied in resolv.conf or the domain derived from the
107 kernel hostname variable.
108
109 ARES_OPT_LOOKUPS char *lookups;
110 The lookups to perform for host queries. lookups
111 should be set to a string of the characters "b" or
112 "f", where "b" indicates a DNS lookup and "f" indi‐
113 cates a lookup in the hosts file.
114
115 ARES_OPT_SOCK_STATE_CB
116 void (*sock_state_cb)(void *data, int s, int read,
117 int write);
118 void *sock_state_cb_data;
119 A callback function to be invoked when a socket
120 changes state. s will be passed the socket whose
121 state has changed; read will be set to true if the
122 socket should listen for read events, and write will
123 be set to true if the socket should listen for write
124 events. The value of sock_state_cb_data will be
125 passed as the data argument.
126
127 ARES_OPT_SORTLIST struct apattern *sortlist;
128 int nsort;
129 A list of IP address ranges that specifies the order
130 of preference that results from ares_gethostbyname
131 should be returned in. Note that this can only be
132 used with a sortlist retrieved via
133 ares_save_options(3) (because struct apattern is
134 opaque); to set a fresh sort list, use
135 ares_set_sortlist(3).
136
137 ARES_OPT_SOCK_SNDBUF
138 int socket_send_buffer_size;
139 The send buffer size to set for the socket.
140
141 ARES_OPT_SOCK_RCVBUF
142 int socket_receive_buffer_size;
143 The receive buffer size to set for the socket.
144
145 ARES_OPT_EDNSPSZ int ednspsz;
146 The message size to be advertized in EDNS; only takes
147 effect if the ARES_FLAG_EDNS flag is set.
148
149 The optmask parameter also includes options without a corresponding
150 field in the ares_options structure, as follows:
151
152 ARES_OPT_ROTATE Perform round-robin selection of the nameservers
153 configured for the channel for each resolution.
154
155 ARES_OPT_NOROTATE Do not perform round-robin nameserver selection;
156 always use the list of nameservers in the same
157 order.
158
159 The flags field should be the bitwise or of some subset of the follow‐
160 ing values:
161
162 ARES_FLAG_USEVC Always use TCP queries (the "virtual circuit")
163 instead of UDP queries. Normally, TCP is only
164 used if a UDP query yields a truncated result.
165
166 ARES_FLAG_PRIMARY Only query the first server in the list of
167 servers to query.
168
169 ARES_FLAG_IGNTC If a truncated response to a UDP query is
170 received, do not fall back to TCP; simply con‐
171 tinue on with the truncated response.
172
173 ARES_FLAG_NORECURSE Do not set the "recursion desired" bit on outgo‐
174 ing queries, so that the name server being con‐
175 tacted will not try to fetch the answer from
176 other servers if it doesn't know the answer
177 locally. Be aware that ares will not do the
178 recursion for you. Recursion must be handled by
179 the application calling ares if ARES_FLAG_NORE‐
180 CURSE is set.
181
182 ARES_FLAG_STAYOPEN Do not close communications sockets when the
183 number of active queries drops to zero.
184
185 ARES_FLAG_NOSEARCH Do not use the default search domains; only
186 query hostnames as-is or as aliases.
187
188 ARES_FLAG_NOALIASES Do not honor the HOSTALIASES environment vari‐
189 able, which normally specifies a file of host‐
190 name translations.
191
192 ARES_FLAG_NOCHECKRESP Do not discard responses with the SERVFAIL,
193 NOTIMP, or REFUSED response code or responses
194 whose questions don't match the questions in the
195 request. Primarily useful for writing clients
196 which might be used to test or debug name
197 servers.
198
199 ARES_FLAG_EDNS Include an EDNS pseudo-resource record (RFC
200 2671) in generated requests.
201
203 ares_init_options(3) can return any of the following values:
204
205 ARES_SUCCESS Initialization succeeded.
206
207 ARES_EFILE A configuration file could not be read.
208
209 ARES_ENOMEM The process's available memory was exhausted.
210
211 ARES_ENOTINITIALIZED
212 c-ares library initialization not yet performed.
213
215 When initializing from /etc/resolv.conf, ares_init_options(3) reads the
216 domain and search directives to allow lookups of short names relative
217 to the domains specified. The domain and search directives override one
218 another. If more that one instance of either domain or search direc‐
219 tives is specified, the last occurrence wins. For more information,
220 please see the resolv.conf(5) manual page.
221
223 ares_init(3), ares_destroy(3), ares_dup(3), ares_library_init(3),
224 ares_save_options(3), ares_set_servers(3), ares_set_sortlist(3)
225
227 Greg Hudson, MIT Information Systems
228 Copyright 1998 by the Massachusetts Institute of Technology.
229 Copyright (C) 2004-2010 by Daniel Stenberg.
230
231
232
233
234 5 March 2010 ARES_INIT(3)