cdnsc-ares

C-ares get ns records


I'm using c-ares for my DNS queries. The problem is, i don't know how to get NS values. I didn't find any examples and docs are not enought for me :(

Man page for ares_parse_ns_reply provides only function description. I've already created my channel and figure out how to make gethostbyname queries:

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

But what do i do next to get MX/NS/AAAA records ?


Solution

  • After many hours:

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