The catch is that we need to look up SRV records and need a reasonable
timeout, which the standard Linux resolver doesn't appear capable of.
RULI stands for Resolver User Layer Interface. It's a library built on top of an asynchronous DNS stub resolver. RULI provides an easy-to-use interface for querying DNS SRV resource records. The goal is to promote wide deployment of SRV-cognizant software. RULI aims to fully support SRV-related standards. There are bindings for PHP, Perl, Guile/Scheme, Java, and Lua. IPv6 is supported.
As side-effect, RULI also provides a general-purpose, event-driven, asynchronous, stub DNS resolver.
Maybe worth a look? I don't know (and I can't seem to 'get through' to http://savannah.nongnu.org where the files are hosted).