[libvirt] [PATCH] virConnectGetHostname: return a fully qualified hostname
Daniel P. Berrange
berrange at redhat.com
Thu Dec 11 10:33:02 UTC 2008
On Wed, Dec 10, 2008 at 07:33:17PM -0800, David Lutterkort wrote:
> The attached patch makes virConnectGetHostname try a little harder to get a
> FQDN on systems where gethostname only returns a short name without a
> domain (which is pretty useless). The behavior is equivalent to 'hostname
> --fqdn'.
>
> > From 2ae57d0c8c68c453b3f9715fcc9f83af0ebe84a0 Mon Sep 17 00:00:00 2001
> From: David Lutterkort <lutter at redhat.com>
> Date: Wed, 10 Dec 2008 18:34:39 -0800
> Subject: [PATCH] virConnectGetHostname: return a fully qualified hostname
>
> Instead of doing the equivalent of 'hostname', do 'hostname --fqdn',
> i.e. try to qualify the local host name by an additional call to
> gethostbyname(3)
> +
> +char *virGetHostname(void)
> +{
> + int r;
> + char hostname[HOST_NAME_MAX+1], *str;
> + struct hostent *he;
> +
> + r = gethostname (hostname, HOST_NAME_MAX+1);
> + if (r == -1)
> + return NULL;
> + if (!(he = gethostbyname(hostname)))
> + return NULL;
Actually, gethostbyname should never be used in any modern code as it is
not thread safe. Instead use getaddrinfo() and the AI_CANONNAME flag
Daniel
--
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
More information about the libvir-list
mailing list