[libvirt] [PATCH 1/7] virutil: Introduce virIsValidHostname

Ján Tomko jtomko at redhat.com
Mon Apr 20 14:58:07 UTC 2015


On Sun, Apr 19, 2015 at 08:49:06PM -0400, John Ferlan wrote:
> Similar to virGetHostname, but this time taking a parameter which is a
> hostname or ipaddress from a <source ... <host name ='%s'.../>... />
> XML property and validating that the name can be resolved.
> 
> Return true or false depending on whether we can ascertain the hostname
> address from calls to 'getnameinfo' and 'getaddrinfo'. Subsequent patches
> will be validating a proposed pool hostname definition against existing
> pool hostnames to ensure they are not the same hostname (and thus having
> two pools looking at the same data)

Why do we need this function? The failure to resolve the host is already handled
by the underlying commands.

I don't think adding all this code just to save us a fork on wrong input is worth it.

> +bool
> +virIsValidHostname(const char *hostname)
> +{
> +    int r;
> +    struct addrinfo hints, *info;
> +
> +    if (STRPREFIX(hostname, "localhost") ||
> +        STREQ(hostname, "127.0.0.1") || STREQ(hostname, "::1"))

getaddrinfo handles these two numeric representations of localhost just
fine, just as the rest of them (see DO_TEST_LOCALHOST in sockettest.c
for a few interesting examples)

Jan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20150420/1d596c4a/attachment-0001.sig>


More information about the libvir-list mailing list