简体   繁体   中英

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?

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.

On Windows, GetAddrInfoW is the correct multi-valued version of gethostbyname.

For RDNS, getnameinfo goes the other way.

GetAddrInfoEx may or may not use SRV records, I haven't been able to find out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM