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