views:

306

answers:

4

Hello all,

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.

A: 

I don't think you can find out which it used, but it uses one from /etc/resolv.conf

Puppe
But nslookup can find, at least i can see which dns server it queries from wireshark but i want find it with coding. Actually i'm trying this just for fun and learning purposes.
systemsfault
A: 

There is an excellent site that explains everything you need to know about socket programming, more of FAQ really and it will help you understand it, ok, most of it governs Windows Sockets, but the principals are the same.

Hope this helps, Best regards, Tom.

tommieb75
A: 

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.

bmargulies
yeah i know dig and also nslookup do the same thing.(Probably i'm going to check their source) /etc/resolv.conf contains the adress of my home router's address which is as usual in a dhcp configuration. Probably
systemsfault
+1  A: 

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.

Chris Cleeland
Yeah i checked the nslookup's source code and noticed that they are using the _res from resolver object.
systemsfault