From patchwork Mon Mar 28 23:44:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 8680701 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D29439FC6A for ; Mon, 28 Mar 2016 23:45:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3DF37201CE for ; Mon, 28 Mar 2016 23:45:08 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1E02C2020F for ; Mon, 28 Mar 2016 23:45:07 +0000 (UTC) Received: from localhost ([::1]:43541 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akgqH-0007ND-CE for patchwork-qemu-devel@patchwork.kernel.org; Mon, 28 Mar 2016 19:45:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42101) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akgq2-0007Jf-0K for qemu-devel@nongnu.org; Mon, 28 Mar 2016 19:44:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1akgpx-0006Ee-Sy for qemu-devel@nongnu.org; Mon, 28 Mar 2016 19:44:49 -0400 Received: from sonata.ens-lyon.org ([140.77.166.138]:47080) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akgpx-0006EB-LN for qemu-devel@nongnu.org; Mon, 28 Mar 2016 19:44:45 -0400 Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id 30705200E6; Tue, 29 Mar 2016 01:44:44 +0200 (CEST) Received: from sonata.ens-lyon.org ([127.0.0.1]) by localhost (sonata.ens-lyon.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tQQpRJRWuLs9; Tue, 29 Mar 2016 01:44:44 +0200 (CEST) Received: from var.youpi.perso.aquilenet.fr (LFbn-1-6757-94.w90-120.abo.wanadoo.fr [90.120.189.94]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by sonata.ens-lyon.org (Postfix) with ESMTPSA id F0B61200D7; Tue, 29 Mar 2016 01:44:43 +0200 (CEST) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.86_2) (envelope-from ) id 1akgpv-0007FK-5W; Tue, 29 Mar 2016 01:44:43 +0200 From: Samuel Thibault To: qemu-devel@nongnu.org Date: Tue, 29 Mar 2016 01:44:36 +0200 Message-Id: <1459208679-27805-3-git-send-email-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.8.0.rc3 In-Reply-To: <1459208679-27805-1-git-send-email-samuel.thibault@ens-lyon.org> References: <1459208679-27805-1-git-send-email-samuel.thibault@ens-lyon.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 140.77.166.138 Cc: thuth@redhat.com, jan.kiszka@siemens.com, jasowang@redhat.com, armbru@redhat.com, Samuel Thibault Subject: [Qemu-devel] [PATCH 2/5] slirp: Split get_dns_addr X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Separate get_dns_addr into get_dns_addr_cached and get_dns_addr_resolv_conf to make conversion to IPv6 easier. Signed-off-by: Samuel Thibault Reviewed-by: Thomas Huth --- slirp/slirp.c | 53 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/slirp/slirp.c b/slirp/slirp.c index 6256c89..2f0d3a3 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -108,7 +108,28 @@ static void winsock_cleanup(void) static struct stat dns_addr_stat; -int get_dns_addr(struct in_addr *pdns_addr) +static int get_dns_addr_cached(struct in_addr *pdns_addr) +{ + struct stat old_stat; + if ((curtime - dns_addr_time) < TIMEOUT_DEFAULT) { + *pdns_addr = dns_addr; + return 0; + } + old_stat = dns_addr_stat; + if (stat("/etc/resolv.conf", &dns_addr_stat) != 0) { + return -1; + } + if ((dns_addr_stat.st_dev == old_stat.st_dev) + && (dns_addr_stat.st_ino == old_stat.st_ino) + && (dns_addr_stat.st_size == old_stat.st_size) + && (dns_addr_stat.st_mtime == old_stat.st_mtime)) { + *pdns_addr = dns_addr; + return 0; + } + return 1; +} + +static int get_dns_addr_resolv_conf(struct in_addr *pdns_addr) { char buff[512]; char buff2[257]; @@ -116,24 +137,6 @@ int get_dns_addr(struct in_addr *pdns_addr) int found = 0; struct in_addr tmp_addr; - if (dns_addr.s_addr != 0) { - struct stat old_stat; - if ((curtime - dns_addr_time) < TIMEOUT_DEFAULT) { - *pdns_addr = dns_addr; - return 0; - } - old_stat = dns_addr_stat; - if (stat("/etc/resolv.conf", &dns_addr_stat) != 0) - return -1; - if ((dns_addr_stat.st_dev == old_stat.st_dev) - && (dns_addr_stat.st_ino == old_stat.st_ino) - && (dns_addr_stat.st_size == old_stat.st_size) - && (dns_addr_stat.st_mtime == old_stat.st_mtime)) { - *pdns_addr = dns_addr; - return 0; - } - } - f = fopen("/etc/resolv.conf", "r"); if (!f) return -1; @@ -173,6 +176,18 @@ int get_dns_addr(struct in_addr *pdns_addr) return 0; } +int get_dns_addr(struct in_addr *pdns_addr) +{ + if (dns_addr.s_addr != 0) { + int ret; + ret = get_dns_addr_cached(pdns_addr); + if (ret <= 0) { + return ret; + } + } + return get_dns_addr_resolv_conf(pdns_addr); +} + #endif static void slirp_init_once(void)