C-ares获取ns记录

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记录呢?

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);

2
ns_c_inns_t_ns 的值在 <arpa/nameser.h> 中定义(基于文档)。 - luismartingil
3
研究做得很好。c-ares文档,用最宽泛的意义来说,是令人沮丧的,缺乏示例(除了一些旧实用程序),而且部分缺失,链接也都坏掉了,网址是http://c-ares.haxx.se/docs.html。真是太遗憾了。 - Nick

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接