From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MeJQf-0007bP-7J for qemu-devel@nongnu.org; Thu, 20 Aug 2009 22:00:33 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MeJQa-0007Ud-GK for qemu-devel@nongnu.org; Thu, 20 Aug 2009 22:00:32 -0400 Received: from [199.232.76.173] (port=58152 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MeJQZ-0007U1-W0 for qemu-devel@nongnu.org; Thu, 20 Aug 2009 22:00:28 -0400 Received: from mail-pz0-f192.google.com ([209.85.222.192]:49427) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MeJQZ-000656-GA for qemu-devel@nongnu.org; Thu, 20 Aug 2009 22:00:27 -0400 Received: by pzk30 with SMTP id 30so28462pzk.4 for ; Thu, 20 Aug 2009 19:00:26 -0700 (PDT) From: Ed Swierk Content-Type: text/plain Date: Thu, 20 Aug 2009 19:00:25 -0700 Message-Id: <1250820025.22019.29.camel@localhost.localdomain> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH 1/2] slirp: Remove our_addr code List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Three problems with our_addr: - It's determined only once when qemu starts, but the address can change (just like the DNS configuration can). - It's supposed to be the IP address of a host network interface, but there's no guarantee that gethostbyname(gethostname()) actually does that: the host might be a laptop that has only a loopback interface up, or the hostname might be localhost.localdomain, etc. - It's useless at best: get_dns_addr() calls it, there's no reason to send DNS requests to a different IP address if you're running a DNS server on the host and resolv.conf points to 127.0.0.1. These problems are easily solved by removing the code. Signed-off-by: Ed Swierk --- diff --git a/slirp/main.h b/slirp/main.h index 28d92d8..9f22fe1 100644 --- a/slirp/main.h +++ b/slirp/main.h @@ -30,7 +30,6 @@ extern char *slirp_tty; extern char *exec_shell; extern u_int curtime; extern fd_set *global_readfds, *global_writefds, *global_xfds; -extern struct in_addr our_addr; extern struct in_addr loopback_addr; extern struct in_addr dns_addr; extern char *username; diff --git a/slirp/slirp.c b/slirp/slirp.c index 827dce7..da04ad1 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -27,8 +27,6 @@ #include "slirp.h" #include "hw/hw.h" -/* host address */ -struct in_addr our_addr; /* host dns address */ struct in_addr dns_addr; /* host loopback address */ @@ -117,8 +115,6 @@ static int get_dns_addr(struct in_addr *pdns_addr) if (sscanf(buff, "nameserver%*[ \t]%256s", buff2) == 1) { if (!inet_aton(buff2, &tmp_addr)) continue; - if (tmp_addr.s_addr == loopback_addr.s_addr) - tmp_addr = our_addr; /* If it's the first one, set it to dns_addr */ if (!found) *pdns_addr = tmp_addr; @@ -149,8 +145,6 @@ static int get_dns_addr(struct in_addr *pdns_addr) static void slirp_init_once(void) { static int initialized; - struct hostent *he; - char our_name[256]; #ifdef _WIN32 WSADATA Data; #endif @@ -168,17 +162,6 @@ static void slirp_init_once(void) loopback_addr.s_addr = htonl(INADDR_LOOPBACK); /* FIXME: This address may change during runtime */ - if (gethostname(our_name, sizeof(our_name)) == 0) { - he = gethostbyname(our_name); - if (he) { - our_addr = *(struct in_addr *)he->h_addr; - } - } - if (our_addr.s_addr == 0) { - our_addr = loopback_addr; - } - - /* FIXME: This address may change during runtime */ if (get_dns_addr(&dns_addr) < 0) { dns_addr = loopback_addr; }