mirror of
https://github.com/norohind/hans.git
synced 2025-06-02 16:41:02 +03:00
fixed -d flag
fixed exit on invalid packet
This commit is contained in:
parent
6ac7f04876
commit
c760898ec6
9
tun.cpp
9
tun.cpp
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user