From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60508) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WJKUi-0002bP-9V for qemu-devel@nongnu.org; Fri, 28 Feb 2014 05:16:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WJKUZ-0002hc-NV for qemu-devel@nongnu.org; Fri, 28 Feb 2014 05:16:40 -0500 Received: from mail-ee0-x230.google.com ([2a00:1450:4013:c00::230]:57604) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WJKUZ-0002hV-GD for qemu-devel@nongnu.org; Fri, 28 Feb 2014 05:16:31 -0500 Received: by mail-ee0-f48.google.com with SMTP id e51so1000930eek.21 for ; Fri, 28 Feb 2014 02:16:30 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 28 Feb 2014 11:16:18 +0100 Message-Id: <1393582579-10366-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1393582579-10366-1-git-send-email-pbonzini@redhat.com> References: <1393582579-10366-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 1/2] socket: treat ipv4=on,ipv6=on uniformly List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kraxel@redhat.com, stefanha@redhat.com In some cases, "ipv4=on,ipv6=on" means "try both kinds of address"; in others, it means "try IPv6 only" just by virtue of how the code is structured. Fix this to make things more consistent, and adjust coding style too. Signed-off-by: Paolo Bonzini --- util/qemu-sockets.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 8818d7c..7a9065b 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -127,10 +127,13 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp) addr = qemu_opt_get(opts, "host"); to = qemu_opt_get_number(opts, "to", 0); - if (qemu_opt_get_bool(opts, "ipv4", 0)) - ai.ai_family = PF_INET; - if (qemu_opt_get_bool(opts, "ipv6", 0)) - ai.ai_family = PF_INET6; + if (qemu_opt_get_bool(opts, "ipv4", 0) != qemu_opt_get_bool(opts, "ipv6", 0)) { + if (qemu_opt_get_bool(opts, "ipv4", 0)) { + ai.ai_family = PF_INET; + } else { + ai.ai_family = PF_INET6; + } + } /* lookup */ if (port_offset) @@ -319,11 +322,12 @@ static struct addrinfo *inet_parse_connect_opts(QemuOpts *opts, Error **errp) return NULL; } - if (qemu_opt_get_bool(opts, "ipv4", 0)) { - ai.ai_family = PF_INET; - } - if (qemu_opt_get_bool(opts, "ipv6", 0)) { - ai.ai_family = PF_INET6; + if (qemu_opt_get_bool(opts, "ipv4", 0) != qemu_opt_get_bool(opts, "ipv6", 0)) { + if (qemu_opt_get_bool(opts, "ipv4", 0)) { + ai.ai_family = PF_INET; + } else { + ai.ai_family = PF_INET6; + } } /* lookup */ @@ -418,10 +422,13 @@ int inet_dgram_opts(QemuOpts *opts, Error **errp) return -1; } - if (qemu_opt_get_bool(opts, "ipv4", 0)) - ai.ai_family = PF_INET; - if (qemu_opt_get_bool(opts, "ipv6", 0)) - ai.ai_family = PF_INET6; + if (qemu_opt_get_bool(opts, "ipv4", 0) != qemu_opt_get_bool(opts, "ipv6", 0)) { + if (qemu_opt_get_bool(opts, "ipv4", 0)) { + ai.ai_family = PF_INET; + } else { + ai.ai_family = PF_INET6; + } + } if (0 != (rc = getaddrinfo(addr, port, &ai, &peer))) { error_setg(errp, "address resolution failed for %s:%s: %s", addr, port, -- 1.8.5.3