I need to build a custom simple non-authoritative caching DNS server in C/C++. Any guidance? Links? Samples? Thanks!
There are a bunch of free software implementations of DNS. You could look at their source code. For example:
The book DNS and BIND might be helpful. And, of course, there are the RFCs that specify DNS, see http://rfc-editor.org/.
Alternately, you could use the Ragel State Machine Compiler to build your server from scratch.
There's no such thing as a "simple" cacheing DNS server, particularly if you want decent security. Recent DNS attacks have shown that the cacheing function in recursive DNS servers is particularly vulnerable.
Re-evaluate whether you actually need local cacheing of your own. If you don't, you're probably better off modifying existing DNS proxy code (such as 'dnsmasq').
If you do want to roll-your-own, there are good libraries such as ldns
which can provide the access to the underlying DNS packets.
I'm using ldns
myself in conjunction with libevent
to implement the Fuzzing DNS server I mentioned in an earlier question.
If you really need to do that (it is a huge work, see Alnitak's reply), start from an existing good program (not a one-man experiment unmaintained for a long time like djbdns) and modify it.
Unbound is probably a reasonable choice for this. (The code base is smaller than BIND's one.)
I wrote a basic DNS server for a job interview under BSD license.
May be someone could find it useful: