Why using getdomainname() to fetch the DNS domain of a box is plain wrong …
Just look at the following examples:
From man getdommainname on Mac OS/X:
GETDOMAINNAME(3) BSD Library Functions Manual GETDOMAINNAME(3)NAME
getdomainname, setdomainname — get/set NIS domain name of current host
From the SUN Solaris API description:
Q:
Why can’t I use getdomainname in libnsl? What should I use instead?
A:
In Solaris, libnsl’s getdomainname() is a private interface, unlike in some other UNIX implementations. In some cases there is an ambiguity about DNS domain vs. NIS domain.A replacement for getdomainname() depends on what it is being used for. In the case of DNS, the traditional way of doing this is to call res_init(3N) and look in a deprecated data structure. This is not supported. To obtain the NIS domain the documented way is to use “sysinfo(SI_SRPC_DOMAIN)”.
From the KDE C++ portability documentation:
Don’t use gethostname() or getdomainname()
gethostname() and getdomainname() are not part of the POSIX specification. Use utsname() instead. It is declared in sys/utsname.h.
From FreeBSD man getdomainname:
GETDOMAINNAME(3) FreeBSD Library Functions Manual GETDOMAINNAME(3)NAME
getdomainname, setdomainname — get/set the NIS domain name of current
hostLIBRARY
Standard C Library (libc, -lc)
From the glibc NEWS FIle:
* The new functions `getdomainname’ and `setdomainname’ fetch or change the
YP/NIS domain name. These are system calls which exist on systems which
have YP (aka NIS).
——–
Now Imagine the following scenario:
Large corporate network, 3 cities, using NIS+
NIS+ domains are hamburg, berlin and toronto
DNS domains and subdomains are: hamburg.corp.com, berlin.corp.com, toronto.corp.com
getdomainname() will allways return hamburg, berlin or toronto depending in which NIS+ domain the box is in. Fun Fun Fun Fun Fun …