C-ares获得ns记录

two*_*e88 2 c dns c-ares

我正在使用c-ares进行DNS查询.问题是,我不知道如何获得NS值.我没有找到任何示例和文档不适合我:(

ares_parse_ns_reply的手册提供功能描述.我已经创建了我的频道并弄清楚如何进行gethostbyname查询:

    // ...
    status = ares_init_options(&channel, &options, optmask);
    if (status != ARES_SUCCESS) {
        printf("ares_init_options: %s\n", ares_strerror(status));
        return EXIT_FAILURE;
    }
    // ...
    ares_gethostbyname(channel, "stackoverflow.com", AF_INET, callback, NULL);
    // ...
Run Code Online (Sandbox Code Playgroud)

但是我接下来要做什么来获得MX/NS/AAAA记录?

two*_*e88 6

几个小时后:

static void callback_ns(void *arg, int status, int timeouts, unsigned char *abuf, int alen)
{
   struct hostent *host = NULL;
   ares_parse_ns_reply(abuf, alen, &host)
   // your result now in "host" variable
}

ares_query(channel, "stackoverflow.com", ns_c_in, ns_t_ns, callback_ns, NULL);
Run Code Online (Sandbox Code Playgroud)

  • `ns_c_in` 和 `ns_t_ns` 值在 <arpa/nameser.h> 中定义(基于 [文档](http://c-ares.haxx.se/ares_query.html)) (2认同)
  • 在研究上做得很好.c-ares文档,一个只能用尽可能最简单的词来表达的术语,由于缺少示例(除了几个旧的实用程序)以及部分缺少连接断开的链接而令人遗憾在http://c-ares.haxx.se/docs.html.真是个耻辱. (2认同)