From patchwork Fri Nov 20 22:31:55 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juergen Lock X-Patchwork-Id: 38945 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D8F62B7B63 for ; Sat, 21 Nov 2009 11:04:39 +1100 (EST) Received: from localhost ([127.0.0.1]:42033 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NBdSv-0001au-5L for incoming@patchwork.ozlabs.org; Fri, 20 Nov 2009 19:04:37 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NBdPR-0000AJ-KA for qemu-devel@nongnu.org; Fri, 20 Nov 2009 19:01:01 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NBdPP-00008o-PK for qemu-devel@nongnu.org; Fri, 20 Nov 2009 19:01:00 -0500 Received: from [199.232.76.173] (port=33129 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NBdPP-00008T-Ep for qemu-devel@nongnu.org; Fri, 20 Nov 2009 19:00:59 -0500 Received: from gelbbaer.kn-bremen.de ([78.46.108.116]:58283 helo=smtp.kn-bremen.de) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NBdPO-0000OY-Mn for qemu-devel@nongnu.org; Fri, 20 Nov 2009 19:00:58 -0500 Received: by smtp.kn-bremen.de (Postfix, from userid 10) id E1A8B1E00718; Sat, 21 Nov 2009 01:00:56 +0100 (CET) Received: from triton8.kn-bremen.de (noident@localhost [127.0.0.1]) by triton8.kn-bremen.de (8.14.3/8.14.3) with ESMTP id nAKMVtaB016682 for ; Fri, 20 Nov 2009 23:31:55 +0100 (CET) (envelope-from nox@triton8.kn-bremen.de) Received: (from nox@localhost) by triton8.kn-bremen.de (8.14.3/8.14.3/Submit) id nAKMVtxa016681 for qemu-devel@nongnu.org; Fri, 20 Nov 2009 23:31:55 +0100 (CET) (envelope-from nox) From: Juergen Lock Date: Fri, 20 Nov 2009 23:31:55 +0100 To: qemu-devel@nongnu.org Message-ID: <20091120223155.GA16665@triton8.kn-bremen.de> References: <20091120221953.GA16319@triton8.kn-bremen.de> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH 3/3] tap-bsd: handle ifname on FreeBSD hosts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Handle ifname on FreeBSD hosts; if no ifname is given, always start the search from tap0. (Simplified/cleaned up version of what has been in the FreeBSD ports for a long time.) Signed-off-by: Juergen Lock --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -49,11 +49,39 @@ int tap_open(char *ifname, int ifname_si char *dev; struct stat s; +#ifdef __FreeBSD__ + /* if no ifname is given, always start the search from tap0. */ + int i; + char dname[100]; + + for (i = 0; i < 10; i++) { + if (*ifname) { + snprintf(dname, sizeof dname, "/dev/%s", ifname); + } else { + snprintf(dname, sizeof dname, "/dev/tap%d", i); + } + TFR(fd = open(dname, O_RDWR)); + if (fd >= 0) { + break; + } + else if (errno == ENXIO || errno == ENOENT) { + break; + } + if (*ifname) { + break; + } + } + if (fd < 0) { + qemu_error("warning: could not open %s (%s): no virtual network emulation\n", dname, strerror(errno)); + return -1; + } +#else TFR(fd = open("/dev/tap", O_RDWR)); if (fd < 0) { fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n"); return -1; } +#endif fstat(fd, &s); dev = devname(s.st_rdev, S_IFCHR);