04f300
needed for rh summit demo, jan tomko should get a better patch in 1.5.1.
04f300
04f300
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
04f300
index fdd8dc4..e3051f3 100644
04f300
--- a/util/qemu-sockets.c
04f300
+++ b/util/qemu-sockets.c
04f300
@@ -61,6 +61,25 @@ QemuOptsList socket_optslist = {
04f300
     },
04f300
 };
04f300
 
04f300
+static int qemu_getaddrinfo(const char *node, const char *service,
04f300
+                            const struct addrinfo *hints,
04f300
+                            struct addrinfo **res)
04f300
+{
04f300
+    int ret;
04f300
+
04f300
+    if (node[0] == '[') {
04f300
+        int len = strlen(node);
04f300
+        if (node[len - 1] == ']') {
04f300
+            char *ipv6_node = g_strndup(node + 1, len - 2);
04f300
+            ret = getaddrinfo(ipv6_node, service, hints, res);
04f300
+            g_free(ipv6_node);
04f300
+            return ret;
04f300
+        }
04f300
+    }
04f300
+
04f300
+    return getaddrinfo(node, service, hints, res);
04f300
+}
04f300
+
04f300
 static int inet_getport(struct addrinfo *e)
04f300
 {
04f300
     struct sockaddr_in *i4;
04f300
@@ -136,7 +155,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)
04f300
     /* lookup */
04f300
     if (port_offset)
04f300
         snprintf(port, sizeof(port), "%d", atoi(port) + port_offset);
04f300
-    rc = getaddrinfo(strlen(addr) ? addr : NULL, port, &ai, &res;;
04f300
+    rc = qemu_getaddrinfo(strlen(addr) ? addr : NULL, port, &ai, &res;;
04f300
     if (rc != 0) {
04f300
         error_setg(errp, "address resolution failed for %s:%s: %s", addr, port,
04f300
                    gai_strerror(rc));
04f300
@@ -328,7 +347,7 @@ static struct addrinfo *inet_parse_connect_opts(QemuOpts *opts, Error **errp)
04f300
     }
04f300
 
04f300
     /* lookup */
04f300
-    rc = getaddrinfo(addr, port, &ai, &res;;
04f300
+    rc = qemu_getaddrinfo(addr, port, &ai, &res;;
04f300
     if (rc != 0) {
04f300
         error_setg(errp, "address resolution failed for %s:%s: %s", addr, port,
04f300
                    gai_strerror(rc));
04f300
@@ -424,7 +443,7 @@ int inet_dgram_opts(QemuOpts *opts, Error **errp)
04f300
     if (qemu_opt_get_bool(opts, "ipv6", 0))
04f300
         ai.ai_family = PF_INET6;
04f300
 
04f300
-    if (0 != (rc = getaddrinfo(addr, port, &ai, &peer))) {
04f300
+    if (0 != (rc = qemu_getaddrinfo(addr, port, &ai, &peer))) {
04f300
         error_setg(errp, "address resolution failed for %s:%s: %s", addr, port,
04f300
                    gai_strerror(rc));
04f300
 	return -1;
04f300
@@ -444,7 +463,7 @@ int inet_dgram_opts(QemuOpts *opts, Error **errp)
04f300
     if (!port || strlen(port) == 0)
04f300
         port = "0";
04f300
 
04f300
-    if (0 != (rc = getaddrinfo(addr, port, &ai, &local))) {
04f300
+    if (0 != (rc = qemu_getaddrinfo(addr, port, &ai, &local))) {
04f300
         error_setg(errp, "address resolution failed for %s:%s: %s", addr, port,
04f300
                    gai_strerror(rc));
04f300
         goto err;
04f300
@@ -506,10 +525,11 @@ InetSocketAddress *inet_parse(const char *str, Error **errp)
04f300
         }
04f300
     } else if (str[0] == '[') {
04f300
         /* IPv6 addr */
04f300
-        if (2 != sscanf(str, "[%64[^]]]:%32[^,]%n", host, port, &pos)) {
04f300
+        if (2 != sscanf(str, "%63[^]]]:%32[^,]%n", host, port, &pos)) {
04f300
             error_setg(errp, "error parsing IPv6 address '%s'", str);
04f300
             goto fail;
04f300
         }
04f300
+        strcat(host, "]");
04f300
         addr->ipv6 = addr->has_ipv6 = true;
04f300
     } else if (qemu_isdigit(str[0])) {
04f300
         /* IPv4 addr */