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