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 开发者_StackOverflow社区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.
I don't think you can find out which it used, but it uses one from /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.
精彩评论