From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KyWII-0002Bb-I0 for qemu-devel@nongnu.org; Fri, 07 Nov 2008 13:42:54 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KyWIH-0002Al-Dd for qemu-devel@nongnu.org; Fri, 07 Nov 2008 13:42:54 -0500 Received: from [199.232.76.173] (port=49346 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KyWIH-0002Ai-90 for qemu-devel@nongnu.org; Fri, 07 Nov 2008 13:42:53 -0500 Received: from smtp-out.google.com ([216.239.45.13]:44691) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KyWIG-0007LY-KK for qemu-devel@nongnu.org; Fri, 07 Nov 2008 13:42:52 -0500 Received: from wpaz5.hot.corp.google.com (wpaz5.hot.corp.google.com [172.24.198.69]) by smtp-out.google.com with ESMTP id mA7IgmlW010682 for ; Fri, 7 Nov 2008 10:42:48 -0800 Received: from qw-out-1920.google.com (qwc5.prod.google.com [10.241.193.133]) by wpaz5.hot.corp.google.com with ESMTP id mA7Ig3DL028026 for ; Fri, 7 Nov 2008 10:42:47 -0800 Received: by qw-out-1920.google.com with SMTP id 5so848090qwc.30 for ; Fri, 07 Nov 2008 10:42:46 -0800 (PST) MIME-Version: 1.0 Date: Fri, 7 Nov 2008 10:42:46 -0800 Message-ID: From: Wan-Teh Chang Content-Type: multipart/mixed; boundary=0015175ce10e855bc1045b1dc7ef Subject: [Qemu-devel] Patch for qemu-0.9.1/slirp/misc.c:getouraddr 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 --0015175ce10e855bc1045b1dc7ef Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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. This patch does not include the necessary change to define HAVE_GETIFADDRS on the platforms that have getifaddrs(). You will need to either use an autoconf test for getifaddrs(), or do something like #if defined(__GLIBC__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) #define HAVE_GETIFADDRS 1 #endif at the top of the qemu-0.9.1/slirp/misc.c file. Wan-Teh Chang --0015175ce10e855bc1045b1dc7ef Content-Type: text/plain; name="getouraddr.txt" Content-Disposition: attachment; filename="getouraddr.txt" Content-Transfer-Encoding: 7bit X-Attachment-Id: f_fn9694w20 --- qemu-0.9.1/slirp/misc.c 2008-10-29 17:33:03.000000000 -0700 +++ qemu-0.9.1/slirp/misc.c 2008-11-03 17:15:51.000000000 -0800 @@ -7,6 +7,9 @@ #define WANT_SYS_IOCTL_H #include +#ifdef HAVE_GETIFADDRS +#include +#endif u_int curtime, time_fasttimo, last_slowtimo; @@ -86,6 +89,26 @@ void getouraddr() { +#ifdef HAVE_GETIFADDRS + struct ifaddrs *ifp; + + if (getifaddrs(&ifp) == 0) { + struct ifaddrs *ifa; + for (ifa = ifp; ifa; ifa = ifa->ifa_next) { + struct sockaddr *sa; + + sa = ifa->ifa_addr; + if (sa->sa_family == AF_INET) { + struct sockaddr_in *sin = (struct sockaddr_in *) sa; + if (sin->sin_addr.s_addr != htonl(INADDR_LOOPBACK)) { + our_addr = sin->sin_addr; + break; + } + } + } + freeifaddrs(ifp); + } +#else char buff[256]; struct hostent *he = NULL; @@ -93,6 +116,7 @@ he = gethostbyname(buff); if (he) our_addr = *(struct in_addr *)he->h_addr; +#endif if (our_addr.s_addr == 0) our_addr.s_addr = loopback_addr.s_addr; } --0015175ce10e855bc1045b1dc7ef--