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 be
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