[libvirt] [PATCH 1/2] util: add wrapper function to check if address string is an ip
Daniel P. Berrange
berrange at redhat.com
Tue Aug 10 13:02:09 UTC 2010
On Tue, Aug 10, 2010 at 02:03:27PM +0200, Daniel Veillard wrote:
> On Tue, Aug 10, 2010 at 07:42:49PM +1000, Justin Clift wrote:
>
> Hum ... I think that it's better to allow virSocketParseAddr() to
> take a NULL Addr pointer it's very simple, I'm attaching the patch
> and then virIsNumericIPAddr(foo) can be replaced by
>
> virSocketParseAddr(foo, NULL, 0)
>
> it also has the extensibility of being able to cope with IPv4 or
> IPv6 only if one need, just by adjusting the hint.
> Am I right ? I see you do more initializations on hints.ai_family
> but the memset means the two functions are just the same for
> ai_socktype and ai_protocol,
Yep, AI_NUMERICHOST is the only one that really matters here.
> diff --git a/src/util/network.c b/src/util/network.c
> index 6e24792..b17d419 100644
> --- a/src/util/network.c
> +++ b/src/util/network.c
> @@ -56,7 +56,7 @@ static int getIPv6Addr(virSocketAddrPtr addr, virIPv6AddrPtr tab) {
> /**
> * virSocketParseAddr:
> * @val: a numeric network address IPv4 or IPv6
> - * @addr: where to store the return value.
> + * @addr: where to store the return value, optional.
> * @hint: optional hint to pass down to getaddrinfo
> *
> * Mostly a wrapper for getaddrinfo() extracting the address storage
> @@ -70,7 +70,7 @@ virSocketParseAddr(const char *val, virSocketAddrPtr addr, int hint) {
> struct addrinfo hints;
> struct addrinfo *res = NULL;
>
> - if ((val == NULL) || (addr == NULL))
> + if (val == NULL)
> return(-1);
>
> memset(&hints, 0, sizeof(hints));
> @@ -80,7 +80,8 @@ virSocketParseAddr(const char *val, virSocketAddrPtr addr, int hint) {
> }
>
> len = res->ai_addrlen;
> - memcpy(&addr->stor, res->ai_addr, len);
> + if (addr != NULL)
> + memcpy(&addr->stor, res->ai_addr, len);
>
> freeaddrinfo(res);
> return(len);
ACK
Daniel
--
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.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