zaplec zaplec - 1 month ago 19x
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:


would return the IPv6 address from 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?


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.