I'd like to be able to add IP addresses for DNS nameservers on Linux from my C/C++ program. I'm on a somewhat embedded platform with a read-only /etc/resolv.conf. This means I can't simply add a "nameserver xxx.xxx.xxx.xxx" line to the file without a little trickery. Are there any clean ways to do this from code?
I could try symlinking /etc/resolv.conf to a file in tmpfs, but that seems hackish and it feels like something I should be able to do without writing to a file.
Have a look at
nsaddr_list
inresolv.conf
from your libc.This question says:
In uClibc 0.9.31 specifically there is a comment on line 533 in
resolv.c
describing how this works.