Reputation: 627
Is there a good API alternative to res_ninit
?
There are problems with this call because the res->_u.ext.nscount6
and res->nscount
do not reflect correct numbers. Adding a IPv6 address to /etc/resolv.conf
still results in the nscount
increasing where you would have expected the nscount6
to increase.
An older glibc version seems to increase both nscount
and nscount6
for a IPv6 address in /etc/resolv.conf
.
I am currently parsing resolv.conf
directly because i am unable to depend on the res_ninit
call. But this is fine for Manual DNS.
When it comes to DHCP DNS, then i need an API to give me the result. There is no other way (that i can think of) to determine the DNS IP addresses over DHCP.
Tried posting in other places within the board but not of help so far. E.g.
Retrieve IPv4 and IPv6 nameservers programmatically
Upvotes: 1
Views: 419
Reputation: 33719
res_ninit
and res_init
only ever read name server information from /etc/resolv.conf
. You can always get the same data name servers by parsing /etc/resolv.conf
yourself and examining the nameserver
lines. If there is no nameserver
line, the default 127.0.0.1
will be used.
I don't think it is necessary to provide an API for that because the file format is so simple that is likely more difficult to use the API than to read the file instead.
Name server assignment over DHCP is implemented by rewriting /etc/resolv.conf
if there is no local caching resolver running on the machine. The exact mechanism used for that is distribution-specific, e.g. Debian uses resolvconf
if it is installed.
If a local caching resolver is running on the system (such as dnsmasq or Unbound), name servers over DHCP can be directly configured in that caching resolver. In this case, /etc/resolv.conf
will keep pointing to the same name server, typically by listing nameserver 127.0.0.1
or no name server information at all (which is the default).
Upvotes: 1