fixed -d flag

fixed exit on invalid packet
This commit is contained in:
Friedrich Schöller 2009-07-31 19:12:57 +02:00
parent 6ac7f04876
commit c760898ec6

View File

@ -28,6 +28,7 @@
#include <syslog.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
typedef ip IpHeader;
@ -39,7 +40,7 @@ Tun::Tun(const char *device, int mtu)
if (device != NULL)
{
strncmp(this->device, device, VTUN_DEV_LEN);
strncpy(this->device, device, VTUN_DEV_LEN);
this->device[VTUN_DEV_LEN] = 0;
}
else
@ -81,7 +82,8 @@ void Tun::write(const char *buffer, int length)
if (tun_write(fd, (char *)buffer, length) == -1)
{
syslog(LOG_ERR, "error writing %d bytes to tun", length);
throw Exception("writing to tun", true);
if (errno != EINVAL) // can be caused by invalid data packet
throw Exception("writing to tun", true);
}
}
@ -89,7 +91,10 @@ int Tun::read(char *buffer)
{
int length = tun_read(fd, buffer, mtu);
if (length == -1)
{
syslog(LOG_ERR, "error reading from tun", length);
throw Exception("reading from tun", true);
}
return length;
}