Don't mean to whore myself, but perhaps some will find this useful (and more
importantly, send patches). A recursive (also stub), reentrant, non-blocking
DNS resolver in a single .c file:

        http://25thandclement.com/~william/projects/dns.c.html

I had been using c-ares for several years, with a gigantic wrapper to
unobfuscate the DNS querying process (for me personally, all existing
libraries fall short of my requirements). Hopefully I've come up w/ a
convenient API which is record-agnostic (i.e. as easy to use SRV records as
A records), and doesn't force the user to contort their code to work in a
non-blocking manner with libevent (no descriptor "vectors" returned--nor
descriptor callbacks--so no convoluted struct event management;
dns_r_pollin() and dns_r_pollout() return the descriptor to wait on). Also
doesn't enforce the callback paradigm, which can also cause headaches when
you pile on three levels of callback indirection; it's easy to use from a
simple state machine.

There are no external dependencies other than BSD sockets; arc4random() and
OpenSSL RAND_get_bytes() are supported but optional. A C99 compiler is
currently required, however, since the record iterators use compound
literals and inline auto declarations. Technically, the iterator macros use
these, so a port to MSC should simply involve refactoring some internal code
to use dns_rr_grep() directly rather than dns_rr_foreach(), replacing
compound literals w/ alloca() or auto variables, and separate definitions of
some auto variables. I might get around to this, but I prefer MinGW on Win32
so don't wait on me.

I haven't yet compiled for Win32, but the code was written with Win32 in
mind (e.g. inet_pton/inet_ntop implementation, etc).

The last part of dns.c is a full regression suite, with example usage for
everything. As yet there is no standalone documentation. To really
stress-test things, build and run the regression utility like so:

        make dns && ./dns -q www.microsoft.com -t MX -v resolve-recurse

Ultimately there's no MX record available, but the excessive CNAME chaining
and out-of-bailiwick nameserver redirections are fun.

In short, it does (or should do) everything but caching. My own usage is
mostly as a stub resolver, but the recursive bit was fairly trivial given
the smart query feature. My smart query wrapper around c-ares is far more
convoluted.

Caveat emptor: Everything was written in the past several weeks, excluding
the permutation generator, which I wrote last year.

If you find it useful, please contribute patches. If I don't roll a patch
into mainline, I'll host the patch on the project website.

_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkeymail.org/mailman/listinfo/libevent-users

Reply via email to