3

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 ?

artyomboyko
  • 2,781
  • 5
  • 40
  • 54

1 Answers1

7

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);
artyomboyko
  • 2,781
  • 5
  • 40
  • 54
  • 2
    `ns_c_in` and `ns_t_ns` values are defined in (based on [documentation](http://c-ares.haxx.se/ares_query.html)) – luismartingil May 30 '14 at 14:44
  • 3
    Well done on the research. The c-ares docs, a term that one can only use in the loosest possible sense of the word, are woeful with a lack of examples (aside from a couple of old utilities) as well as partly missing with broken links all over the place at http://c-ares.haxx.se/docs.html. Really a shame. – Nick Apr 02 '16 at 11:41