简体   繁体   中英

how to get DNS server in c-ares

I'm using c-ares-1.10.0 which is a C library for asynchronous DNS requests ,it's a good lib to do name resolves~ Now I have a question when I use c-ares~

there is multi nameserver in "/etc/resolv.conf" such as nameserver 1.1.1.1 nameserver 2.2.2.2

I want to get Dns server which c-ares used to do dns query,1.1.1.1 or 2.2.2.2, But I can't find the API in c-ares docs~ Does any one know how to get dns server?

Use this function from ares.h:

CARES_EXTERN int ares_get_servers(ares_channel channel,
                                  struct ares_addr_node **servers);

The servers can also be retrieved with the

  int ares_save_options(ares_channel channel, struct ares_options *options, int *optmask)) 

function , as members of struct ares_option , though I believe that can only contain IPv4 server addresses, while ares_get_servers() can provide you with both IPv4/IPv6 servers.

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