evdns(3) | Library Functions Manual | evdns(3) |
Welcome, gentle reader.
The library keeps track of the state of nameservers and will avoid them when they go down. Otherwise it will round robin between them.
Quick start guide: #include 'evdns.h' void callback(int result, char type, int count, int ttl, void *addresses, void *arg); evdns_resolv_conf_parse(DNS_OPTIONS_ALL, '/etc/resolv.conf'); evdns_resolve('www.hostname.com', 0, callback, NULL);
When the lookup is complete the callback function is called. The first argument will be one of the DNS_ERR_* defines in evdns.h. Hopefully it will be DNS_ERR_NONE, in which case type will be DNS_IPv4_A, count will be the number of IP addresses, ttl is the time which the data can be cached for (in seconds), addresses will point to an array of uint32_t's and arg will be whatever you passed to evdns_resolve.
Searching:
In order for this library to be a good replacement for glibc's resolver it supports searching. This involves setting a list of default domains, in which names will be queried for. The number of dots in the query name determines the order in which this list is used.
Searching appears to be a single lookup from the point of view of the API, although many DNS queries may be generated from a single call to evdns_resolve. Searching can also drastically slow down the resolution of names.
To disable searching:
The order of searches depends on the number of dots in the name. If the number is greater than the ndots setting then the names is first tried globally. Otherwise each search domain is appended in turn.
The ndots setting can either be set from a resolv.conf, or by calling evdns_search_ndots_set.
For example, with ndots set to 1 (the default) and a search domain list of ['myhome.net']: Query: www Order: www.myhome.net, www.
Query: www.abc Order: www.abc., www.abc.myhome.net
Internals:
Requests are kept in two queues. The first is the inflight queue. In this queue requests have an allocated transaction id and nameserver. They will soon be transmitted if they haven't already been.
The second is the waiting queue. The size of the inflight ring is limited and all other requests wait in waiting queue for space. This bounds the number of concurrent requests so that we don't flood the nameserver. Several algorithms require a full walk of the inflight queue and so bounding its size keeps thing going nicely under huge (many thousands of requests) loads.
If a nameserver loses too many requests it is considered down and we try not to use it. After a while we send a probe to that nameserver (a lookup for google.com) and, if it replies, we consider it working again. If the nameserver fails a probe we wait longer to try again with the next probe.
Parameters:
Returns:
Parameters:
Returns:
See Also:
Parameters:
Returns:
See Also:
Parameters:
See Also:
Note that only evdns_getaddrinfo uses the /etc/hosts entries.
Return 0 on success, negative on failure.
Parameters:
Returns:
See Also:
If no port is specified, it defaults to 53.
Parameters:
Returns:
See Also:
Parameters:
Returns:
See Also:
The following directives are not parsed from the file: sortlist, rotate, no-check-names, inet6, debug.
If this function encounters an error, the possible return values are: 1 = failed to open file, 2 = failed to stat file, 3 = file too large, 4 = out of memory, 5 = short read from file, 6 = no nameservers listed in the file
Parameters:
Returns:
See Also:
Returns:
See Also:
Returns:
See Also:
Returns:
See Also:
Returns:
See Also:
Parameters:
Returns:
See Also:
Returns:
See Also:
Parameters:
ndots, timeout, max-timeouts, max-inflight, attempts, randomize-case, bind-to, initial-probe-timeout, getaddrinfo-allow-skew.
In versions before Libevent 2.0.3-alpha, the option name needed to end with a colon.
Parameters:
Returns:
See Also:
Returns:
When the callback is invoked, we pass as its first argument the error code that getaddrinfo would return (or 0 for no error). As its second argument, we pass the evutil_addrinfo structures we found (or NULL on error). We pass 'arg' as the third argument.
Limitations:
Parameters:
NOTE: This function has no effect in Libevent 2.0.4-alpha and later, since Libevent now provides its own secure RNG.
Parameters:
NOTE: This function has no effect in Libevent 2.0.4-alpha and later, since Libevent now provides its own secure RNG.
Wed Apr 10 2013 | libevent |