tags:

views:

1272

answers:

6

I need to build a custom simple non-authoritative caching DNS server in C/C++. Any guidance? Links? Samples? Thanks!

A: 

Start with djbdns.

Hank Gay
I would be careful about that. djb's software has very restrictive licenses. make sure that it agrees with your intended use.
TokenMacGuy
djbdns is now public domain, but I still wouldn't use it...
Alnitak
+1  A: 

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/.

Lars Wirzenius
A: 

Alternately, you could use the Ragel State Machine Compiler to build your server from scratch.

Hank Gay
State machine is a very small part of a server's code...
bortzmeyer
For something defined by a very strict spec like a DNS server, it's a substantial (and arguably the most important) part.
Hank Gay
+4  A: 

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.

Alnitak
A: 

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.)

bortzmeyer
Note for the readers: remember to ignore downvotes if there is not a comment to explain them.
bortzmeyer
I don't see how djbdns qualifies as a 'one-man experiment' when at one time it was the second most used DNS server.The djbdns community seems to be doing a fine job of maintaining stock djbdns via patches against the last official version. There are also at least four maintained forks for those looking for a pre-patched version.
Mark Johnson
djb's software has regularly been known to behave contrary to standards because of his general belief that his way is better than the standards, and he has also been known to deny the existence of serious remote privilege elevation bugs in his code. Along with the long period during which djbdns was completely unmaintained, I think these factors make it perfectly fair for bortzmeyer to call it "a one-man experiement unmaintained for a long time" and discourage its deployment on non-hobbyist environments.
R..
A: 

I wrote a basic DNS server for a job interview under BSD license.

May be someone could find it useful:

http://code.google.com/p/dns-server/

tomasorti