The ares_init_options(3) function initializes a communications channel for name service lookups. If it returns successfully, ares_init_options(3) will set the variable pointed to by channelptr to a handle used to identify the name service channel. The caller should invoke ares_destroy(3) on the handle when the channel is no longer needed.

The optmask parameter generally specifies which fields in the structure pointed to by options are set, as follows:

inttimeout;The number of seconds each name server is given to respond to a query on the first try. (After the first try, the timeout algorithm becomes more complicated, but scales linearly with the value of timeout.) The default is five seconds. This option is being deprecated by ARES_OPT_TIMEOUTMS starting in c-ares 1.5.2.

inttimeout;The number of milliseconds each name server is given to respond to a query on the first try. (After the first try, the timeout algorithm becomes more complicated, but scales linearly with the value of timeout.) The default is five seconds. Note that this option is specified with the same struct field as the former ARES_OPT_TIMEOUT, it is but the option bits that tell c-ares how to interpret the number. This option was added in c-ares 1.5.2.

intndots;The number of dots which must be present in a domain name for it to be queried for "as is" prior to querying for it with the default domain extensions appended. The default value is 1 unless set otherwise by resolv.conf or the RES_OPTIONS environment variable.

struct in_addr *servers;intnservers;The list of IPv4 servers to contact, instead of the servers specified in resolv.conf or the local named. In order to allow specification of either IPv4 or IPv6 name servers, the ares_set_servers(3) function must be used instead.

void (*sock_state_cb)(void *data, int s, int read, int write);void *sock_state_cb_data;A callback function to be invoked when a socket changes state. s will be passed the socket whose state has changed; read will be set to true if the socket should listen for read events, and write will be set to true if the socket should listen for write events. The value of sock_state_cb_data will be passed as the data argument.

struct apattern *sortlist;intnsort;A list of IP address ranges that specifies the order of preference that results from ares_gethostbyname should be returned in. Note that this can only be used with a sortlist retrieved via ares_save_options(3) (because struct apattern is opaque); to set a fresh sort list, use ares_set_sortlist(3).

Do not set the "recursion desired" bit on outgoing queries, so that the name server being contacted will not try to fetch the answer from other servers if it doesn't know the answer locally. Be aware that ares will not do the recursion for you. Recursion must be handled by the application calling ares if ARES_FLAG_NORECURSE is set.

Do not discard responses with the SERVFAIL, NOTIMP, or REFUSED response code or responses whose questions don't match the questions in the request. Primarily useful for writing clients which might be used to test or debug name servers.

When initializing from /etc/resolv.conf, ares_init_options(3) reads the domain and search directives to allow lookups of short names relative to the domains specified. The domain and search directives override one another. If more that one instance of either domain or search directives is specified, the last occurrence wins. For more information, please see the resolv.conf(5) manual page.