From owner-freebsd-questions@FreeBSD.ORG Thu May 15 18:51:15 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AC378106566B for ; Thu, 15 May 2008 18:51:15 +0000 (UTC) (envelope-from rvm@CBORD.com) Received: from smssmtp.cbord.com (mx1.cbord.com [24.39.174.11]) by mx1.freebsd.org (Postfix) with ESMTP id 611D78FC16 for ; Thu, 15 May 2008 18:51:14 +0000 (UTC) (envelope-from rvm@CBORD.com) X-AuditID: ac1f0165-00000d9c000002f4-ed-482c85eb373b Received: from Email.cbord.com ([10.1.1.100]) by smssmtp.cbord.com with Microsoft SMTPSVC(6.0.3790.1830); Thu, 15 May 2008 14:50:19 -0400 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Date: Thu, 15 May 2008 14:49:26 -0400 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Unable to talk to tap(4) Thread-Index: Aci2Cx2biwXR13CRR3mYtR+pRdCrswAfIomwAAz2m4A= References: <20080514234101.P2316@wojtek.tensor.gdynia.pl> From: "Bob McConnell" To: X-Brightmail-Tracker: AAAAAA== Subject: RE: Unable to talk to tap(4) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 May 2008 18:51:15 -0000 From: Bob McConnell=20 >From: Wojciech Puchar >>> >>> The basic setup sequence is: >>> >>> ifconfig tap0 create >>> ifconfig tap0 inet 10.3.4.254/24 >>> route -v add 10.3.4.0/24 10.3.4.254 >> >> ifconfig tap0 up >> >> ? >> > > 'ifconfig' already showed the interface flag UP. Adding this command > to the sequence has no effect on it. I also tried 'ifconfig tap0 promisc'. > > Is EFAULT really a memory access exception? > >>> >>> At this point, I can ping that address and my application can open >>> either /dev/net/tap0 or /dev/tap0. But when I try to read() from those >>> devices, I have problems. >>> >>> /dev/net/tap0 always returns with errno =3D 19 (ENODEV - Operation = not >>> supported?). >>> >>> /dev/tap0 returns errno =3D 14 (EFAULT - bad address). At this = point, >>> 'ifconfig' shows that the inet address is no longer attached and >>> 'netstat -rn' shows the route I added above has been dropped. >>> >>> I have been searching for several days to find more information about >>> this device, but have not found anything specific to FreeBSD. All of the >>> examples and instructions are for Linux or tun(4), both of which are >>> significantly different devices. >>> >>> My code so far: >>> >>> ----------------- tear along dotted line ----------------- >>> tapFD =3D open ("/dev/tap0", O_RDWR); >>> if (tapFD < 0) { >>> fprintf (stderr, "Failed to open /dev/tap0: %d.\n", tapFD); >>> exit (2); >>> } >>> >>> fprintf (stderr, "Successfully opened /dev/tap0.\n"); >>> >>> unsigned char * buffer =3D (unsigned char*)malloc(1514); >>> if (buffer =3D NULL) { >>> fprintf (stderr, "No memory available.\n"); >>> close (tapFD); >>> exit(3); >>> } When I replace the malloc with an automatic array, the error goes away and I get the data I am looking for. i.e.: unsigned char buffer[1514]; So why can't I use malloc to create that buffer? >>> int lenth =3D 0; >>> >>> again: >>> lenth =3D read(tapFD, buffer, 1514); >>> if (lenth < 0) { >>> int error =3D errno; >>> if (error =3D=3D EINTR) >>> goto again; >>> fprintf (stderr, "tap read error: %d\n", error); >>> } >>> else { >>> int index; >>> >>> fprintf (stdout, "%d bytes received.\n", lenth); >>> for (index =3D 0; index < lenth; ++index) { >>> fprintf (stdout, " %02x", buffer[index]); >>> if (index % 16 =3D=3D 15) >>> fprintf (stdout, "\n"); >>> } >>> fprintf (stdout, "\n"); >>> } >>> >>> close (tapFD); >>> ----------------- tear along dotted line ----------------- >>> >>> Just in the interest of full disclosure, I am running a stock >>> installation of FreeBSD 7.0 in a VMWare 5.5.4 session on WinXP. There >>> are also two virtual Ethernet cards, one connected to a host only >>> subnet, the other bridged onto a real Ethernet segment. I am using IPFW >>> with DummyNet to inject some measure of reality into this system. >>> >>> This is the beginnings of a test bench for several commercial >>> applications. My goal, once I get this device working, is to write an >>> application for tap(4) that will emulate a few hundred embedded devices, >>> each opening a socket directly to a server, which currently resides in >>> another VM session on the host only network. This setup, coupled with >>> real devices on the external network should give us a much more >>> realistic environment for stress testing our systems. >>> >>> Thank you, >>> >>> Bob McConnell