1ARES_INIT(3)               Library Functions Manual               ARES_INIT(3)
2
3
4

NAME

6       ares_init_options - Initialize a resolver channel
7

SYNOPSIS

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         char *resolvconf_path;
31         char *hosts_path;
32         int udp_max_queries;
33       };
34
35       int ares_init_options(ares_channel *channelptr,
36                             struct ares_options *options,
37                             int optmask)
38

DESCRIPTION

40       The  ares_init_options(3) function initializes a communications channel
41       for name service lookups.  If it  returns  successfully,  ares_init_op‐
42       tions(3)  will  set  the  variable pointed to by channelptr to a handle
43       used to identify the name service channel.  The  caller  should  invoke
44       ares_destroy(3) on the handle when the channel is no longer needed.
45
46       The optmask parameter generally specifies which fields in the structure
47       pointed to by options are set, as follows:
48
49       ARES_OPT_FLAGS    int flags;
50                         Flags controlling the behavior of the resolver.   See
51                         below for a description of possible flag values.
52
53       ARES_OPT_TIMEOUT  int timeout;
54                         The  number  of  seconds each name server is given to
55                         respond to a query on  the  first  try.   (After  the
56                         first try, the timeout algorithm becomes more compli‐
57                         cated, but scales linearly with the  value  of  time‐
58                         out.)  The default is two seconds. This option is be‐
59                         ing deprecated by ARES_OPT_TIMEOUTMS starting  in  c-
60                         ares 1.5.2.
61
62       ARES_OPT_TIMEOUTMS
63                         int timeout;
64                         The  number of milliseconds each name server is given
65                         to respond to a query on the first try.   (After  the
66                         first try, the timeout algorithm becomes more compli‐
67                         cated, but scales linearly with the  value  of  time‐
68                         out.)  The default is two seconds. Note that this op‐
69                         tion is specified with the same struct field  as  the
70                         former  ARES_OPT_TIMEOUT,  it  is but the option bits
71                         that tell c-ares how to interpret  the  number.  This
72                         option was added in c-ares 1.5.2.
73
74       ARES_OPT_TRIES    int tries;
75                         The  number of tries the resolver will try contacting
76                         each name server before giving up.   The  default  is
77                         three tries.
78
79       ARES_OPT_NDOTS    int ndots;
80                         The  number of dots which must be present in a domain
81                         name for it to be queried for "as is" prior to query‐
82                         ing  for  it  with  the default domain extensions ap‐
83                         pended.  The default value is 1 unless set  otherwise
84                         by  resolv.conf  or the RES_OPTIONS environment vari‐
85                         able.
86
87       ARES_OPT_UDP_PORT unsigned short udp_port;
88                         The port to use for queries over UDP,  in  host  byte
89                         order.   The  default  value is 53, the standard name
90                         service port.
91
92       ARES_OPT_TCP_PORT unsigned short tcp_port;
93                         The port to use for queries over TCP,  in  host  byte
94                         order.   The  default  value is 53, the standard name
95                         service port.
96
97       ARES_OPT_SERVERS  struct in_addr *servers;
98                         int nservers;
99                         The list of IPv4 servers to contact, instead  of  the
100                         servers  specified in resolv.conf or the local named.
101                         In order to allow specification  of  either  IPv4  or
102                         IPv6 name servers, the 0 instead.
103
104       ARES_OPT_DOMAINS  char **domains;
105                         int ndomains;
106                         The  domains to search, instead of the domains speci‐
107                         fied in resolv.conf or the domain  derived  from  the
108                         kernel hostname variable.
109
110       ARES_OPT_LOOKUPS  char *lookups;
111                         The  lookups  to  perform  for host queries.  lookups
112                         should be set to a string of the  characters  "b"  or
113                         "f",  where  "b" indicates a DNS lookup and "f" indi‐
114                         cates a lookup in the hosts file.
115
116       ARES_OPT_SOCK_STATE_CB
117                         void   (*sock_state_cb)(void   *data,   ares_socket_t
118                         socket_fd, int readable, int writable);
119                         void *sock_state_cb_data;
120                         A  callback  function  to  be  invoked  when a socket
121                         changes state.  socket_fd will be passed  the  socket
122                         whose state has changed; readable will be set to true
123                         if the socket should  listen  for  read  events,  and
124                         writable  will  be  set  to true if the socket should
125                         listen   for   write   events.     The    value    of
126                         sock_state_cb_data  will  be passed as the data argu‐
127                         ment.
128
129       ARES_OPT_SORTLIST struct apattern *sortlist;
130                         int nsort;
131                         A list of IP address ranges that specifies the  order
132                         of  preference  that  results from ares_gethostbyname
133                         should be returned in.  Note that this  can  only  be
134                         used  with  a  sortlist  retrieved  via ares_save_op‐
135                         tions(3) (because struct apattern is opaque); to  set
136                         a fresh sort list, use ares_set_sortlist(3).
137
138       ARES_OPT_SOCK_SNDBUF
139                         int socket_send_buffer_size;
140                         The send buffer size to set for the socket.
141
142       ARES_OPT_SOCK_RCVBUF
143                         int socket_receive_buffer_size;
144                         The receive buffer size to set for the socket.
145
146       ARES_OPT_EDNSPSZ  int ednspsz;
147                         The message size to be advertized in EDNS; only takes
148                         effect if the ARES_FLAG_EDNS flag is set.
149
150       ARES_OPT_RESOLVCONF
151                         char *resolvconf_path;
152                         The path to use for reading the resolv.conf file. The
153                         resolvconf_path  should  be set to a path string, and
154                         will be honoured on *nix like systems. The default is
155                         /etc/resolv.conf
156
157       ARES_OPT_HOSTS_FILE
158                         char *hosts_path;
159                         The  path  to  use  for  reading  the hosts file. The
160                         hosts_path should be set to a path string,  and  will
161                         be  honoured  on  *nix  like  systems. The default is
162                         /etc/hosts
163
164       ARES_OPT_UDP_MAX_QUERIES
165                         int udp_max_queries;
166                         The maximum number of udp queries that can be sent on
167                         a  single ephemeral port to a given DNS server before
168                         a new ephemeral port is assigned.  Any value of 0  or
169                         less  will  be  considered  unlimited, and is the de‐
170                         fault.
171
172       The optmask parameter also includes  options  without  a  corresponding
173       field in the ares_options structure, as follows:
174
175       ARES_OPT_ROTATE        Perform round-robin selection of the nameservers
176                              configured for the channel for each resolution.
177
178       ARES_OPT_NOROTATE      Do not perform round-robin nameserver selection;
179                              always  use  the list of nameservers in the same
180                              order.
181
182       The flags field should be the bitwise or of some subset of the  follow‐
183       ing values:
184
185       ARES_FLAG_USEVC        Always  use  TCP queries (the "virtual circuit")
186                              instead of UDP queries.  Normally, TCP  is  only
187                              used if a UDP query yields a truncated result.
188
189       ARES_FLAG_PRIMARY      Only  query  the  first  server  in  the list of
190                              servers to query.
191
192       ARES_FLAG_IGNTC        If a truncated response to a UDP  query  is  re‐
193                              ceived, do not fall back to TCP; simply continue
194                              on with the truncated response.
195
196       ARES_FLAG_NORECURSE    Do not set the "recursion desired" bit on outgo‐
197                              ing  queries, so that the name server being con‐
198                              tacted will not try to  fetch  the  answer  from
199                              other  servers if it doesn't know the answer lo‐
200                              cally. Be aware that ares will not do the recur‐
201                              sion  for you.  Recursion must be handled by the
202                              application calling ares if  ARES_FLAG_NORECURSE
203                              is set.
204
205       ARES_FLAG_STAYOPEN     Do  not  close  communications  sockets when the
206                              number of active queries drops to zero.
207
208       ARES_FLAG_NOSEARCH     Do not use  the  default  search  domains;  only
209                              query hostnames as-is or as aliases.
210
211       ARES_FLAG_NOALIASES    Do  not  honor the HOSTALIASES environment vari‐
212                              able, which normally specifies a file  of  host‐
213                              name translations.
214
215       ARES_FLAG_NOCHECKRESP  Do  not  discard  responses  with  the SERVFAIL,
216                              NOTIMP, or REFUSED response  code  or  responses
217                              whose questions don't match the questions in the
218                              request.  Primarily useful for  writing  clients
219                              which  might  be  used  to  test  or  debug name
220                              servers.
221
222       ARES_FLAG_EDNS         Include  an  EDNS  pseudo-resource  record  (RFC
223                              2671) in generated requests.
224

RETURN VALUES

226       ares_init_options(3) can return any of the following values:
227
228       ARES_SUCCESS  Initialization succeeded.
229
230       ARES_EFILE    A configuration file could not be read.
231
232       ARES_ENOMEM   The process's available memory was exhausted.
233
234       ARES_ENOTINITIALIZED
235                     c-ares library initialization not yet performed.
236

NOTES

238       When initializing from /etc/resolv.conf, (or, alternatively when speci‐
239       fied by the resolvconf_path path location)  ares_init_options(3)  reads
240       the  domain and search directives to allow lookups of short names rela‐
241       tive to the domains specified. The domain and search  directives  over‐
242       ride  one another. If more than one instance of either domain or search
243       directives is specified, the last occurrence wins.  For  more  informa‐
244       tion, please see the resolv.conf(5) manual page.
245

SEE ALSO

247       ares_init(3),   ares_destroy(3),   ares_dup(3),   ares_library_init(3),
248       ares_save_options(3), ares_set_servers(3), ares_set_sortlist(3)
249

AUTHOR

251       Greg Hudson, MIT Information Systems
252       Copyright 1998 by the Massachusetts Institute of Technology.
253       Copyright (C) 2004-2010 by Daniel Stenberg.
254
255
256
257                                 5 March 2010                     ARES_INIT(3)
Impressum