3

我正在使用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);
    // ...

但是接下来我该怎么做才能获得 MX/NS/AAAA 记录?

4

1 回答 1

7

几个小时后:

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);
于 2012-06-10T16:59:57.323 回答