zaplec zaplec - 3 months ago 39
C++ Question

How to do DNS AAAA, CNAME and SRV lookups in C++?

I need to a little program in C++ that takes the type and hostname as commandline parameters and then makes the DNS lookup. For example:

DNSapp AAAA www.google.com


would return the IPv6 address from www.google.com and so on.

I can do the simple A lookup just by using the gethostbyname, but I have no idea how to perform those other lookups. I've tried to google them, but with no success. Any ideas how to do that?

Answer

gethostbyname is obsolete, use getaddrinfo for A / AAAA lookups.

For SRV etc I recommend ldns, or the related libunbound. The latter is a full resolver in a library.

You could also just use res_search from the Linux standard library.