I'm trying to retrieve the local domain suffix of my host programmatically in ANSI C (Linux). Eg: my machine is ironside.0ffnet.net, I'd like to retrieve "0ffnet.net".
I've seen a number of posts addressing this by using getnameinfo() and getaddrinfo(), however it appears that these functions pull their information from the /etc/hosts file for any interface addresses local to the machine.
If my machine is allocated an address (and corresponding domain suffix) via DHCP, the /etc/hosts file does not get updated, instead this information is stored in /etc/resolv.conf e.g.:
dfex@ironside:~/hush$cat /etc/resolv.conf
domain 0ffnet.net
search 0ffnet.net
nameserver 139.130.4.4
as a result, both getnameinfo() and getaddrinfo() simply return the hostname of the machine, without the suffix, using the /etc/hosts info, which looks like:
dfex@ironside:~/hush$ cat /etc/hosts
::1 ironside localhost6.localdomain6 localhost6
127.0.1.1 ironside
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
Does anybody know of a function that will pull this information without resorting to system() calls? I've been combing through Beej's guide without much success.