在 Linux/Unix/Posix/BSD 类型系统上解析 DNS TXT 记录的最佳方法?
我想编写一些可移植(尽可能)的 C 代码来查找 DNS TXT 记录。我也不想依赖于机器不附带的库。
在使用标准库的类 Unix 机器上执行此操作的最佳方法是什么?
我找到了一些使用 libresolv 工作的示例代码,但它不是可重入的(不是线程安全的)并且非常丑陋。有更好的办法吗?
另外,Windows 呢?如果有一种方法也能在那里发挥作用那就完美了。
I want to write some portable (as possible) C code to look up DNS TXT records. I would also prefer not to have dependencies on libraries that don't ship with the machine.
What is the best way to do this on Unix-like machines using standard libraries?
I found some sample code that works using libresolv, but it's not reentrant (not thread safe) and is very ugly. Is there a better way?
Also, what about Windows? If there were a way that worked there too that would be perfect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用使用标准 libresolv 的 res_query 。
有一个 示例如下 来自克拉马夫:
you can use res_query which uses the standard libresolv.
There's an example here from clamav:
这是常见问题解答。请参阅执行直接 DNS 查找的代码或如何在 Linux 上使用 C/C++ 执行 DNS 查找? 。
This is a FAQ. See Code to do a direct DNS lookup or How might I perform DNS lookups using C/C++ on Linux?.