From: Wan-Teh Chang <wtc@google.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] Patch for qemu-0.9.1/slirp/misc.c:getouraddr
Date: Fri, 7 Nov 2008 10:42:46 -0800 [thread overview]
Message-ID: <e8c553a60811071042radc9459r3b53564795473bda@mail.gmail.com> (raw)
[-- 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;
}
next reply other threads:[~2008-11-07 18:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-07 18:42 Wan-Teh Chang [this message]
2008-11-09 11:43 ` [Qemu-devel] Patch for qemu-0.9.1/slirp/misc.c:getouraddr Blue Swirl
2008-11-10 18:04 ` Wan-Teh Chang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e8c553a60811071042radc9459r3b53564795473bda@mail.gmail.com \
--to=wtc@google.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).