简体   繁体   中英

How to get the address of the DNS server that getaddrinfo queries

I'm newbie to BSD socket programming in C. I can query a web address to get its associated ip addresses with "getaddrinfo" function. But i want to know which dns server getaddrinfo queries this information from.

If you are on linux or a unix platform, try looking at man -k resolver and look for the resolver man page or a page for functions like res_init , res_search , et. al. Those are the unix APIs to DNS, and it looks like, while there's no direct way to do what you want to do, one could glean the information through a combination of the functions and what they return, and doing a few other massaging of data.

With regard to wireshark knowing what's going on, it doesn't really know. It's just monitoring packets as they flow to and fro and printing out what it sees. The resolver is what knows, and that's the API I suggested.

我认为您无法找到它使用了哪个,但是它使用了/etc/resolv.conf中的一个

If you are on Linux, you can look at the source to 'dig'. Based on it's ability to print out the server address, I think there must be some means to do this other than just parsing the /etc/resolv.conf.

On Windows, there is a very convoluted API for the purpose.

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