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.
GetNetworkParams
/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 entry nsaddr_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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With