问题
I need to build a custom simple non-authoritative caching DNS server in C/C++. Any guidance? Links? Samples? Thanks!
回答1:
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.
回答2:
I wrote a basic DNS server for a job interview under BSD license.
May be someone could find it useful:
https://github.com/tomasorti/dns-server
回答3:
There are a bunch of free software implementations of DNS. You could look at their source code. For example:
- http://cr.yp.to/djbdns.html
- http://www.isc.org/products/BIND/
The book DNS and BIND might be helpful. And, of course, there are the RFCs that specify DNS, see http://rfc-editor.org/.
回答4:
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.)
回答5:
Start with djbdns.
回答6:
Alternately, you could use the Ragel State Machine Compiler to build your server from scratch.
来源:https://stackoverflow.com/questions/649618/how-to-build-a-custom-simple-dns-server-in-c-c