Using C++, I would like to obtain the DNS servers being used by a host for three operating systems: OS X, FreeBSD, and Windows. I’d like confirmation that the approaches below are indeed best practice, and if not, a superior alternative.
- OS X: already answered; updated link at developer.apple.com
- Windows:
GetNetworkParams - FreeBSD:
/etc/resolv.conf
Thanks in advance for your help!
On many unix systems (linux, bsd) you can use the resolver functions to obtain the list of DNS servers: man 3 resolver.
After calling
res_init()the resolver structure is initialized. The resolver structure stores all the information you need. The list of DNS servers are stored in the struct entrynsaddr_list.The exact specification of the resolver structure can most likely be found in
resolv.h.Using the resolver functions is the preferred way to obtain the list of DNS servers.
res_init()will most likely fill the resolver structure with the information found in/etc/resolv.conf.Also see Use of resolv.h