qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] Patch for qemu-0.9.1/slirp/misc.c:getouraddr
@ 2008-11-07 18:42 Wan-Teh Chang
  2008-11-09 11:43 ` Blue Swirl
  0 siblings, 1 reply; 3+ messages in thread
From: Wan-Teh Chang @ 2008-11-07 18:42 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 566 bytes --]

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

[-- Attachment #2: getouraddr.txt --]
[-- Type: text/plain, Size: 1153 bytes --]

--- 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 <slirp.h>
+#ifdef HAVE_GETIFADDRS
+#include <ifaddrs.h>
+#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;
 }

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-11-10 18:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-07 18:42 [Qemu-devel] Patch for qemu-0.9.1/slirp/misc.c:getouraddr Wan-Teh Chang
2008-11-09 11:43 ` Blue Swirl
2008-11-10 18:04   ` Wan-Teh Chang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).