Fix tapdev

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@342 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2007-09-14 23:53:29 +00:00
parent c0d812555f
commit c4e326ea5f
3 changed files with 24 additions and 15 deletions

View File

@ -112,7 +112,7 @@ extern char *up_deviceimage(void);
#ifdef CONFIG_NET
extern unsigned long up_getwalltime( void );
extern void tapdev_init(void);
extern unsigned int tapdev_read(char *buf, unsigned int buflen);
extern unsigned int tapdev_read(unsigned char *buf, unsigned int buflen);
extern void tapdev_send(char *buf, unsigned int buflen);
#endif

View File

@ -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);
}
}

View File

@ -106,7 +106,7 @@ void uipdriver_loop(void)
{
int i;
uip_len = tapdev_read((char*)uip_buf, UIP_BUFSIZE);
uip_len = tapdev_read((unsigned char*)uip_buf, UIP_BUFSIZE);
if (uip_len > 0)
{
if (BUF->type == htons(UIP_ETHTYPE_IP))