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