如何在 C/C++ 中构建自定义的简单 DNS 服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/649618/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 16:29:05  来源:igfitidea点击:

How to Build a custom simple DNS server in C/C++

c++cdns

提问by Anton Kopylov

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

我需要在 C/C++ 中构建一个自定义的简单非权威缓存 DNS 服务器。任何指导?链接?样品?谢谢!

回答by Alnitak

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.

没有“简单”缓存 DNS 服务器这样的东西,特别是如果您想要体面的安全性。最近的 DNS 攻击表明递归 DNS 服务器中的缓存功能特别容易受到攻击。

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

重新评估您是否真的需要自己的本地缓存。如果不这样做,最好修改现有的 DNS 代理代码(例如“dnsmasq”)。

If you do want to roll-your-own, there are good libraries such as ldnswhich can provide the access to the underlying DNS packets.

如果您确实想自己动手,有一些很好的库,例如ldns可以提供对底层 DNS 数据包的访问。

I'm using ldnsmyself in conjunction with libeventto implement the Fuzzing DNS server I mentioned in an earlier question.

我将ldns自己与libevent我在前面的问题中提到的 Fuzzing DNS 服务器结合使用。

回答by nephewtom

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

我为 BSD 许可下的求职面试编写了一个基本的 DNS 服务器。

May be someone could find it useful:

可能有人会发现它很有用:

https://github.com/tomasorti/dns-server

https://github.com/tomasorti/dns-server

回答by Anton Kopylov

There are a bunch of free software implementations of DNS. You could look at their source code. For example:

有许多免费的 DNS 软件实现。你可以看看他们的源代码。例如:

The book DNS and BINDmight be helpful. And, of course, there are the RFCs that specify DNS, see http://rfc-editor.org/.

DNS 和 BIND一书可能会有所帮助。而且,当然,还有指定 DNS 的 RFC,请参阅http://rfc-editor.org/

回答by bortzmeyer

If you really need to do that (it is a hugework, see Alnitak's reply), start from an existing goodprogram (not a one-man experiment unmaintained for a long time like djbdns) and modify it.

如果您真的需要这样做(这是一项巨大的工作,请参阅 Alnitak 的回复),请从现有的程序(而不是像 djbdns 这样长时间无人维护的单人实验)开始并对其进行修改。

Unboundis probably a reasonable choice for this. (The code base is smaller than BIND's one.)

Unbound可能是一个合理的选择。(代码库比 BIND 的代码库小。)

回答by Hank Gay

Start with djbdns.

djbdns开始。

回答by Hank Gay

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

或者,您可以使用Ragel 状态机编译器从头开始构建您的服务器。