qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 1/2] socket: treat ipv4=on,ipv6=on uniformly


From: Paolo Bonzini
Subject: [Qemu-devel] [PATCH 1/2] socket: treat ipv4=on,ipv6=on uniformly
Date: Fri, 28 Feb 2014 11:16:18 +0100

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 <address@hidden>
---
 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]