dns.c 20120805

A recursive, reentrant DNS Resolver
dns.c is a reentrant, recursive and non-blocking DNS resolver library that resides in a sincle .c file. Also works great as a stub resolver.

Core API built around actual DNS packet; as generic as DNS itself. This makes querying and manipulating records other than A, AAAA, and PTR much easier.

Restartable record iterators with user-specified sorting. Iterating over MX or SRV records in semantic order (i.e. preference and priority) is as simple as:

dns_rr_foreach(&rr, packet, .type = DNS_T_SRV, .sort = &dns_rr_i_order) {

Or in a restartable manner:

switch (my->state) {
case 0:
  my->rr_i.type = DNS_T_SRV;
  my->rr_i.sort = &dns_rr_i_order;
case 1:
  while (dns_rr_grep(&rr, 1, &my->rr_i, my->packet, &error)) {
    /* return into event loop */

Supports "smart" queries. When enabled in the core resolver, queries for NS, MX, and SRV records will always attempt to resolve the RDATA canonical host name into an A record. Hosts which are not in-bailiwick and/or for which the authoritative server does not provide glue are automagically resolved and returned in the answer packet. Supported for both stub and recursive resolver instantiations. "Smart" resolution is also built into the address info (i.e. getaddrinfo()) API.

Randomized source ports and QIDs.

Non-blocking, re-entrant, iterator-based getaddrinfo() interface: dns_ai_open(), dns_ai_nextent(), dns_ai_close(). Semantically just like getaddrinfo(), but also takes a record type. Iterate over (struct addrinfo) objects even when querying an MX, NS, SRV (et al) host. There is less latency doing "smart" queries this way, since any necessary recursion can be postponed (and in all likelihood won't be necessary, since the first host is likely sufficient).

last updated on:
August 8th, 2012, 14:34 GMT
license type:
developed by:
William Ahern
ROOT \ Internet \ DNS
Download Button

In a hurry? Add it to your Download Basket!

user rating



Rate it!
What's New in version 20110114
  • Fix bug where dns_srv_print() failed to print a trailing NUL character.
read full changelog

Add your review!