我正在使用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记录?
几个小时后:
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)