From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kzb7i-0003lf-Ba for qemu-devel@nongnu.org; Mon, 10 Nov 2008 13:04:26 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kzb7f-0003k9-QF for qemu-devel@nongnu.org; Mon, 10 Nov 2008 13:04:25 -0500 Received: from [199.232.76.173] (port=36653 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kzb7f-0003jy-Fe for qemu-devel@nongnu.org; Mon, 10 Nov 2008 13:04:23 -0500 Received: from smtp-out.google.com ([216.239.33.17]:47868) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Kzb7e-0007iW-Ph for qemu-devel@nongnu.org; Mon, 10 Nov 2008 13:04:23 -0500 Received: from zps18.corp.google.com (zps18.corp.google.com [172.25.146.18]) by smtp-out.google.com with ESMTP id mAAI4Fef013434 for ; Mon, 10 Nov 2008 18:04:15 GMT Received: from qw-out-2122.google.com (qwe3.prod.google.com [10.241.194.3]) by zps18.corp.google.com with ESMTP id mAAI4D6i002688 for ; Mon, 10 Nov 2008 10:04:14 -0800 Received: by qw-out-2122.google.com with SMTP id 3so1757164qwe.47 for ; Mon, 10 Nov 2008 10:04:12 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: Date: Mon, 10 Nov 2008 10:04:12 -0800 Message-ID: Subject: Re: [Qemu-devel] Patch for qemu-0.9.1/slirp/misc.c:getouraddr From: Wan-Teh Chang Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org On Sun, Nov 9, 2008 at 3:43 AM, Blue Swirl wrote: > On 11/7/08, Wan-Teh Chang wrote: >> Attached is a patch for qemu-0.9.1/slirp/misc.c to implement >> the getouraddr() function using the BSD function getifaddrs(), >> which is also available in glibc on Linux. > > How is this better than the current way? Does this change something on > hosts with multiple interfaces? What if some interfaces are down? The current way gets the local host's IP addresses by calling gethostbyname, which is usually implemented with a DNS lookup. So the current way usually requires a network request, and it cannot get the IP addresses of a host that doesn't have a name. On hosts with multiple interfaces, the patch may change the order in which the addresses are listed. Since both the current way and the patch just take the first (non-loopback) address on the list, the patch could change the address chosen by getouraddr. If some interfaces are down, I believe the current way can't detect that, whereas this patch can be enhanced to detect that. I believe that we can test the ifa_flags field of the ifaddrs structure to see if the IFF_UP flag (or the IFF_RUNNING flag?) is set. Wan-Teh Chang