Reputation: 383
I'm working on some code that will check DNS records using libresolv.
I first do the query with res_query and that succeeds, but if I'm checking an 'A' record, dn_expand will not give me the IP address back (and I don't think I should really expect it to). However, I have not been able to find a function that will decode the IP address from an rr
How can I get the IP?
I can post some code if needed.
Upvotes: 0
Views: 590
Reputation: 383
The way to do this is to take the rdata from the rr (using res_rr_rdata(rr) ), and run it through inet_ntop.
For an A record, this is what I ended with:
if (ns_parserr(&msg, ns_s_an, rrnum, &rr)) {
printf("ns_parserr: %s\n", strerror(errno));
}
if(ns_rr_type(rr) == ns_t_cname){
printf("Found cname\n");
}
inet_ntop(AF_INET, ns_rr_rdata(rr), decodedBuffer, NS_MAXDNAME);
decodedBuffer ends up with the ip. Obviously for AAAA, use AF_INET6
Upvotes: 1