If I am understanding correct, you are saying that we should set addr->has_ipv6 and addr->has_ipv4 to true in any case, then in my opinion we should simply ignore the value of addr->has_ipv* while evaluating the value of ipv4 and ipv6 variables in inet_addr_to_opts (bool ipv4 = addr->ipv4; bool ipv6 = addr->ipv6). And the "if (!ipv4 || !ipv6)" condition seems really strange to me.
Regards, Umair Sair -----Original Message----- From: Peter Maydell [mailto:peter.mayd...@linaro.org] Sent: Friday, October 02, 2015 10:57 PM To: Sair, Umair Cc: qemu-disc...@nongnu.org; Paolo Bonzini; QEMU Developers Subject: Re: [Qemu-discuss] TCP options ipv4 and ipv6 have no effect (looping in qemu-devel and Paolo) On 2 October 2015 at 17:54, Sair, Umair <umair_s...@mentor.com> wrote: > I am working with qemu-2.4.0. I built it using mingw on Windows. I am > having a problem while connecting it to gdb. I figured out that qemu > gdb server is running on IPv6 whereas gdb tries to connect on IPv4. > This problem is already reported here: > https://bugs.launchpad.net/qemu/+bug/562107. > > gdd server runs on IPv6 even if I provide ipv4 tcp option (-S -gdb > tcp::10000,ipv4). In other words, providing ipv4 or ipv6 option have > no effect on both windows and linux. On linux it always runs on IPv4 > and on Windows, it always runs on IPv6. Can you please help me out in > resolving this problem? > > I debugged qemu a bit and it seems to me that the problem is in > ‘inet_addr_to_opts()’ function of ‘qemu-sockets.c’. Following is the > excerpt from this function: > > static void inet_addr_to_opts(QemuOpts *opts, const InetSocketAddress > *addr) { > > bool ipv4 = addr->ipv4 || !addr->has_ipv4; > bool ipv6 = addr->ipv6 || !addr->has_ipv6; > > if (!ipv4 || !ipv6) { > qemu_opt_set_bool(opts, "ipv4", ipv4); > qemu_opt_set_bool(opts, "ipv6", ipv6); > } > > The ipv4 and ipv6 variables of this function are always true (because > we set > addr->ipv4 = addr->has_ipv4 and addr->ipv6 = addr->has_ipv6), hence > addr->ipv4 and > ipv6 option is never set in the if condition. The consequence is that > the socket is created with PF_UNSPEC and then for windows IPv6 and for > linux > IPv4 socket is created (see inet_listen_opts() in qemu-sockets.c). Is > there a particular reason for the logic of inet_addr_to_opts()? I'm not sure, but something definitely seems weird here; either inet_parse or inet_addr_to_opts is wrong, I think. Paolo, you wrote this code I think; any idea? My guess is that inet_parse should be setting addr->has_ipv6 to true (leaving addr->ipv6 false) if it decides it should be using IPv4 (and vice-versa for IPv6). inet_addr_to_opts I think is correct where it does: bool ipv4 = addr->ipv4 || !addr->has_ipv4; because this is saying "try ipv4 if specifically asked, or if the caller didn't specify either way". I don't know why we have the "if (!ipv4 || !ipv6)" condition on the setting of the opts, though. thanks -- PMM