diff --git a/tun.cpp b/tun.cpp index 4c95680..3293a70 100644 --- a/tun.cpp +++ b/tun.cpp @@ -28,6 +28,7 @@ #include #include #include +#include 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; }