Re: Unable to talk to tap(4)
On Thu, 15 May 2008 14:49:26 -0400 Bob McConnell [EMAIL PROTECTED] wrote: My code so far: - tear along dotted line - tapFD = 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 = (unsigned char*)malloc(1514); if (buffer = NULL) { if (buffer == 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? ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Unable to talk to tap(4)
unsigned char * buffer = (unsigned char*)malloc(1514); is stdlib.h included (i'm asking for sure)? if (buffer = NULL) { if (buffer == 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? anyway not using malloc is good habit :) but it should work anyway. try buffer[0]=buffer[1513]=0; to make sure page is actually allocated. if this help - maybe tap driver is buggy. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Unable to talk to tap(4)
Bob McConnell [EMAIL PROTECTED] writes: From: Bob McConnell 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 = 19 (ENODEV - Operation not supported?). /dev/tap0 returns errno = 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 = 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 = (unsigned char*)malloc(1514); if (buffer = 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? Maybe you forgot to include stdlib.h? That could end up with the compiler adjusting the parameters incorrectly. Incidentally, this problem is why casting the return value of malloc is discouraged; the compiler would warn about such a problem if the (completely unnecessary) cast were not present. int lenth = 0; again: lenth = read(tapFD, buffer, 1514); if (lenth 0) { int error = errno; if (error == EINTR) goto again; fprintf (stderr, tap read error: %d\n, error); } else { int index; fprintf (stdout, %d bytes received.\n, lenth); for (index = 0; index lenth; ++index) { fprintf (stdout, %02x, buffer[index]); if (index % 16 == 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 ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] -- Lowell Gilbert, embedded/networking software engineer, Boston area http://be-well.ilk.org/~lowell/ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
RE: Unable to talk to tap(4)
From: Wojciech Puchar if (buffer = NULL) { if (buffer == NULL) { anyway not using malloc is good habit :) but it should work anyway. try The test after the malloc was the problem. I have been working in a poorly designed scripting language for several months where the single '=' is used for comparisons and didn't see the difference when I got back into C. Setting a pointer to NULL should always cause an EFAULT. Unfortunately, even 'gcc -Wall' didn't generate an appropriate warning for it. I only use malloc when I won't know how many buffers I need until run time. In this case the application will count records in a configuration file and malloc (1514 * count * 2) bytes, where count can range from 1 to 2000. That becomes an array of buffers, so I can pass just an index or pointer between threads, usually through a mailbox or message queue. It's a simple trick for message passing that I picked up years ago while using the CTASK and XINU kernels. Thanks for all the help, Bob McConnell ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
RE: Unable to talk to tap(4)
On Fri, 16 May 2008, Bob McConnell wrote: From: Wojciech Puchar if (buffer = NULL) { if (buffer == NULL) { anyway not using malloc is good habit :) but it should work anyway. try The test after the malloc was the problem. I have been working in a :) ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
RE: Unable to talk to tap(4)
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 = 19 (ENODEV - Operation not supported?). /dev/tap0 returns errno = 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 = 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 = (unsigned char*)malloc(1514); if (buffer = NULL) { fprintf (stderr, No memory available.\n); close (tapFD); exit(3); } int lenth = 0; again: lenth = read(tapFD, buffer, 1514); if (lenth 0) { int error = errno; if (error == EINTR) goto again; fprintf (stderr, tap read error: %d\n, error); } else { int index; fprintf (stdout, %d bytes received.\n, lenth); for (index = 0; index lenth; ++index) { fprintf (stdout, %02x, buffer[index]); if (index % 16 == 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 ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
RE: Unable to talk to tap(4)
From: Bob McConnell 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 = 19 (ENODEV - Operation not supported?). /dev/tap0 returns errno = 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 = 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 = (unsigned char*)malloc(1514); if (buffer = 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 = 0; again: lenth = read(tapFD, buffer, 1514); if (lenth 0) { int error = errno; if (error == EINTR) goto again; fprintf (stderr, tap read error: %d\n, error); } else { int index; fprintf (stdout, %d bytes received.\n, lenth); for (index = 0; index lenth; ++index) { fprintf (stdout, %02x, buffer[index]); if (index % 16 == 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 ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Unable to talk to tap(4)
Good morning, Does anyone here have experience using tap(4)? I am trying to do some basic I/O with it, but am not having any success. I have gotten to the point where I can create and configure the device, and my application can open it, but read() always returns errors. 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 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 = 19 (ENODEV - Operation not supported?). /dev/tap0 returns errno = 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 = 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 = (unsigned char*)malloc(1514); if (buffer = NULL) { fprintf (stderr, No memory available.\n); close (tapFD); exit(3); } int lenth = 0; again: lenth = read(tapFD, buffer, 1514); if (lenth 0) { int error = errno; if (error == EINTR) goto again; fprintf (stderr, tap read error: %d\n, error); } else { int index; fprintf (stdout, %d bytes received.\n, lenth); for (index = 0; index lenth; ++index) { fprintf (stdout, %02x, buffer[index]); if (index % 16 == 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 Principal Communications Programmer The CBORD Group, Inc. 61 Brown Road Ithaca NY, 14850 Phone 607 257-2410 FAX 607 257-1902 Email [EMAIL PROTECTED] Web www.cbord.com ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Unable to talk to tap(4)
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 ? 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 = 19 (ENODEV - Operation not supported?). /dev/tap0 returns errno = 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 = 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 = (unsigned char*)malloc(1514); if (buffer = NULL) { fprintf (stderr, No memory available.\n); close (tapFD); exit(3); } int lenth = 0; again: lenth = read(tapFD, buffer, 1514); if (lenth 0) { int error = errno; if (error == EINTR) goto again; fprintf (stderr, tap read error: %d\n, error); } else { int index; fprintf (stdout, %d bytes received.\n, lenth); for (index = 0; index lenth; ++index) { fprintf (stdout, %02x, buffer[index]); if (index % 16 == 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 Principal Communications Programmer The CBORD Group, Inc. 61 Brown Road Ithaca NY, 14850 Phone 607 257-2410 FAX 607 257-1902 Email [EMAIL PROTECTED] Web www.cbord.com ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]