Hi all!

Quoting Linus Torvalds ([EMAIL PROTECTED]):

> And even the ones that use domainname tend to not have a fully qualified 
> DNS domain there. You need to use dnsdomainname to get that, and I don't 
> even know how to do it with standard libc.

I don't think getdomainname should be used at all in this case as it is the
domain name used by NIS and it might be different from the DNS domain name
in the FQDN associated with a given host. I just looked into the domainname
manual page and it agrees with me:

 domainname,  nisdomainname,  ypdomainname  will  print the name of the
 system as returned by the getdomainname(2) function.  This is also known as
 the YP/NIS domain name of the system.

That's why it is set to "(none)" (i.e. its not setup at all) on most hosts
because if they're not running NIS it's not really needed.

To get the FQDN which is what we want you'd have to use something like
this:

#include <netdb.h>
#include <unistd.h>

char *getfqdn(void)
{
        static char hostname[HOST_NAME_MAX + 1];
        struct hostent *hp;

        if (gethostname(hostname, sizeof(hostname)) < 0)
        {
                /* error handling */
        }

        if (!(hp = gethostbyname(hostname)))
        {
                /* just return the possibly unqualified hostname */
                return hostname;
        }

        return  hp->h_name;
}

Cheers,
Lars.
-- 
Lars Fenneberg, [EMAIL PROTECTED] (private), [EMAIL PROTECTED] (work)
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to