views:

814

answers:

4

I'm thinking of running an experiment to track DNS values in different ways (like how often they change and whatnot). To do this I will need to be able to make a DNS request directly to a server so that 1) I known what server it came from, 2) I can request responses from several servers and 3) I can avoid the local OS run cache.

Does anyone know of a library (c#, D, C, C++ in that order of preference) that will let me directly query a DNS server? Failing that, does anyone know of a easy to understand description of the DNS protocol that I could implement such a system from?

+2  A: 

For C, I'd go with http://cr.yp.to/djbdns/blurb/library.html (the low-level parts if you need total control, i.e. dns_transmit* and friends) -- for C#, maybe http://www.c-sharpcorner.com/UploadFile/ivxivx/DNSClient12122005234612PM/DNSClient.aspx (can't test that one right now, whence the "maybe"!).

Alex Martelli
I can't download the c# one <grrr/> but the C one looks good so far.
BCS
The C one is Unix only (I can live with that but it's not my first choice)
BCS
The djb library seems unable to do IPv6 lookups or, simply, to do lookups for arbitrary resource recode types such as NAPTR or SRV.
bortzmeyer
A: 

libdns (I think it's part of bind). There's a cygwin port which may be useful for windows environments.

http://rpm2html.osmirror.nl/libdns.so.21.html

SpliFF
In the Windows world there is this nice function named DNSQuery()http://msdn.microsoft.com/en-us/library/ms682016%28VS.85%29.aspx
Jason
+2  A: 

I have experience only with C, so here is my list:

  • libresolv is the old, traditional and standard way. It is available on every Unix (type man 3 resolver) and includes routines like res_query which does more or less what you want. To query a specific name server, you typically update the global variable _res.nsaddr_list (do note that, apparently, it does not work with IPv6).

  • ldns is the modern and shiny solution. You have good documentation online.

  • a very common library, but apparently unmaintained, is adns.

bortzmeyer
+1 for ldns - it's what I use in my own code.
Alnitak
Then, do not forget to publish it to provide nice examples for the newcomers :-)
bortzmeyer
I will, soon! :)
Alnitak
+1  A: 

The DNS specification is spread over many RFC (see a nice graph) and I would strongly advise not to implement a stub resolver from scratch. There are many opportunities to get it wrong. The DNS evolved a lot in the last years. If you are brave and crazy, here are the most important RFC:

  • RFC 1034, concepts
  • RFC 1035, format
  • RFC 2181, update to the specification, to fix many errors or ambiguities
  • RFC 2671, EDNS (mandatory today)
  • RFC 3597, handling the unknown resource record types
  • and many others...
bortzmeyer
I'm not /that/ crazy!
BCS