The problem is that there is no reliable way how to get correct FQDN.
There is unreliable interface getdomainname() which returns on many
platforms empty string or often default domains like "localdomain",
"mydomain" when no other specific domain was set during system
installation. The getdomainname() takes the value on some platforms
from sysctl, on other platforms from file in /etc/ and on other
platforms it's completely ignored. The name service lookup is not
reliable as well - it depends on how the name service was set (usually
NSS switch uses local files first which often have the shortname in
front of longname for the given IP address and thus return often
shortname first).