在 Linux/Unix/Posix/BSD 类型系统上解析 DNS TXT 记录的最佳方法?

发布于 2024-08-22 08:23:53 字数 209 浏览 1 评论 0原文

我想编写一些可移植(尽可能)的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨落星ぅ辰 2024-08-29 08:23:53

您可以使用使用标准 libresolv 的 res_query

有一个 示例如下 来自克拉马夫:

if((len = res_query(domain, C_IN, T_TXT, answer, PACKETSZ)) < 0) {
  mprintf("@Can't query %s\n", domain);
  return NULL;
}

you can use res_query which uses the standard libresolv.

There's an example here from clamav:

if((len = res_query(domain, C_IN, T_TXT, answer, PACKETSZ)) < 0) {
  mprintf("@Can't query %s\n", domain);
  return NULL;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文