diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-09-14 23:53:29 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-09-14 23:53:29 +0000 |
commit | 8bd136d2202c6706ac2166a31b90f1ec18139dea (patch) | |
tree | d78d7e4f1feb0b5982fbbcf709d247822fdac63a /nuttx/arch/sim/src/up_tapdev.c | |
parent | cfb41fb64f57f0c6864254c6048f8d2967b6f60c (diff) | |
download | px4-nuttx-8bd136d2202c6706ac2166a31b90f1ec18139dea.tar.gz px4-nuttx-8bd136d2202c6706ac2166a31b90f1ec18139dea.tar.bz2 px4-nuttx-8bd136d2202c6706ac2166a31b90f1ec18139dea.zip |
Fix tapdev
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@342 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/arch/sim/src/up_tapdev.c')
-rw-r--r-- | nuttx/arch/sim/src/up_tapdev.c | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/nuttx/arch/sim/src/up_tapdev.c b/nuttx/arch/sim/src/up_tapdev.c index f07b118e6..f742afeac 100644 --- a/nuttx/arch/sim/src/up_tapdev.c +++ b/nuttx/arch/sim/src/up_tapdev.c @@ -185,11 +185,12 @@ unsigned long up_getwalltime( void ) void tapdev_init(void) { char buf[1024]; + int ret; gtapdevfd = up_open(DEVTAP, O_RDWR, 0644); - if(gtapdevfd == -1) + if (gtapdevfd < 0) { - lib_rawprintf("tapdev: tapdev_init: open"); + lib_rawprintf("TAPDEV: open failed: %d\n", -gtapdevfd ); return; } @@ -198,25 +199,32 @@ void tapdev_init(void) struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TAP|IFF_NO_PI; - if (up_ioctl(gtapdevfd, TUNSETIFF, (unsigned long *) &ifr) < 0) + ret = up_ioctl(gtapdevfd, TUNSETIFF, (unsigned long *) &ifr); + if (ret < 0) { - lib_rawprintf(buf); + lib_rawprintf("TAPDEV: ioctl failed: %d\n", -ret ); return; } } #endif /* Linux */ - lib_rawprintf(buf, sizeof(buf), "ifconfig tap0 inet %d.%d.%d.%d", - UIP_DRIPADDR0, UIP_DRIPADDR1, UIP_DRIPADDR2, UIP_DRIPADDR3); + snprintf(buf, sizeof(buf), "ifconfig tap0 inet %d.%d.%d.%d\n", + UIP_DRIPADDR0, UIP_DRIPADDR1, UIP_DRIPADDR2, UIP_DRIPADDR3); system(buf); } -unsigned int tapdev_read(char *buf, unsigned int buflen) +unsigned int tapdev_read(unsigned char *buf, unsigned int buflen) { fd_set fdset; struct timeval tv; int ret; + /* We can't do anything if we failed to open the tap device */ + if (gtapdevfd < 0) + { + return 0; + } + tv.tv_sec = 0; tv.tv_usec = 1000; @@ -230,18 +238,19 @@ unsigned int tapdev_read(char *buf, unsigned int buflen) } ret = up_read(gtapdevfd, buf, buflen); - if(ret == -1) + if (ret < 0) { - lib_rawprintf("tap_dev: tapdev_read: read"); + lib_rawprintf("TAPDEV: read failed: %d\n", -ret); + return 0; } #ifdef TAPDEV_DEBUG - lib_rawprintf("tap_dev: tapdev_read: read %d bytes\n", ret); + lib_rawprintf("TAPDEV: read %d bytes\n", ret); { int i; for(i = 0; i < 20; i++) { - lib_rawprintf("%x ", buf[i]); + lib_rawprintf("%02x ", buf[i]); } lib_rawprintf("\n"); } @@ -265,9 +274,9 @@ void tapdev_send(char *buf, unsigned int buflen) #endif ret = up_write(gtapdevfd, buf, buflen); - if(ret == -1) + if (ret < 0) { - perror("tap_dev: tapdev_send: write"); + lib_rawprintf("TAPDEV: write"); exit(1); } } |