mirror of
https://github.com/norohind/hans.git
synced 2025-06-17 15:50:59 +03:00
fixed -d flag
fixed exit on invalid packet
This commit is contained in:
parent
6ac7f04876
commit
c760898ec6
7
tun.cpp
7
tun.cpp
@ -28,6 +28,7 @@
|
|||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
typedef ip IpHeader;
|
typedef ip IpHeader;
|
||||||
|
|
||||||
@ -39,7 +40,7 @@ Tun::Tun(const char *device, int mtu)
|
|||||||
|
|
||||||
if (device != NULL)
|
if (device != NULL)
|
||||||
{
|
{
|
||||||
strncmp(this->device, device, VTUN_DEV_LEN);
|
strncpy(this->device, device, VTUN_DEV_LEN);
|
||||||
this->device[VTUN_DEV_LEN] = 0;
|
this->device[VTUN_DEV_LEN] = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -81,6 +82,7 @@ void Tun::write(const char *buffer, int length)
|
|||||||
if (tun_write(fd, (char *)buffer, length) == -1)
|
if (tun_write(fd, (char *)buffer, length) == -1)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, "error writing %d bytes to tun", length);
|
syslog(LOG_ERR, "error writing %d bytes to tun", length);
|
||||||
|
if (errno != EINVAL) // can be caused by invalid data packet
|
||||||
throw Exception("writing to tun", true);
|
throw Exception("writing to tun", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,7 +91,10 @@ int Tun::read(char *buffer)
|
|||||||
{
|
{
|
||||||
int length = tun_read(fd, buffer, mtu);
|
int length = tun_read(fd, buffer, mtu);
|
||||||
if (length == -1)
|
if (length == -1)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "error reading from tun", length);
|
||||||
throw Exception("reading from tun", true);
|
throw Exception("reading from tun", true);
|
||||||
|
}
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user