]> xenbits.xensource.com Git - libvirt.git/commitdiff
Extend virSocketParseAddr() to allow a NULL result pointer
authorDaniel Veillard <veillard@redhat.com>
Tue, 10 Aug 2010 13:00:15 +0000 (15:00 +0200)
committerDaniel Veillard <veillard@redhat.com>
Tue, 10 Aug 2010 13:00:15 +0000 (15:00 +0200)
That way it can be used to verify a numeric address without storing
the details
* src/util/network.c: change virSocketParseAddr to allow a null @addr
  parameter

src/util/network.c

index 6e24792ff1c632671ac7cdcc5b53031fc3e0139b..b17d4196302cb42747d547998c4f736b23229458 100644 (file)
@@ -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);