mirror of
https://github.com/norohind/hans.git
synced 2025-04-21 00:17:37 +03:00
Improved tun error reporting
This commit is contained in:
parent
3459887cf7
commit
b58ad1bee8
@ -30,6 +30,11 @@ Exception::Exception(const char *msg)
|
||||
this->msg = msg;
|
||||
}
|
||||
|
||||
Exception::Exception(const string msg)
|
||||
{
|
||||
this->msg = msg;
|
||||
}
|
||||
|
||||
Exception::Exception(const char *msg, bool appendSystemError)
|
||||
{
|
||||
if (appendSystemError)
|
||||
|
@ -23,8 +23,9 @@ class Exception
|
||||
{
|
||||
public:
|
||||
Exception(const char *msg);
|
||||
Exception(const std::string msg);
|
||||
Exception(const char *msg, bool appendSystemError);
|
||||
|
||||
|
||||
const char *errorMessage() const { return msg.c_str(); }
|
||||
protected:
|
||||
std::string msg;
|
||||
|
@ -28,7 +28,6 @@
|
||||
#include <syslog.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef ip IpHeader;
|
||||
@ -49,7 +48,7 @@ Tun::Tun(const char *device, int mtu)
|
||||
|
||||
fd = tun_open(this->device);
|
||||
if (fd == -1)
|
||||
throw Exception("could not create tunnel device");
|
||||
throw Exception(string("could not create tunnel device: ") + tun_last_error());
|
||||
|
||||
char cmdline[512];
|
||||
snprintf(cmdline, sizeof(cmdline), "/sbin/ifconfig %s mtu %u", this->device, mtu);
|
||||
@ -90,14 +89,14 @@ void Tun::setIp(uint32_t ip, uint32_t destIp, bool includeSubnet)
|
||||
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: %s", length, strerror(errno));
|
||||
syslog(LOG_ERR, "error writing %d bytes to tun: %s", length, tun_last_error());
|
||||
}
|
||||
|
||||
int Tun::read(char *buffer)
|
||||
{
|
||||
int length = tun_read(fd, buffer, mtu);
|
||||
if (length == -1)
|
||||
syslog(LOG_ERR, "error reading from tun: %s", strerror(errno));
|
||||
syslog(LOG_ERR, "error reading from tun: %s", tun_last_error());
|
||||
return length;
|
||||
}
|
||||
|
||||
|
@ -24,4 +24,5 @@ extern "C"
|
||||
int tun_close(int fd, char *dev);
|
||||
int tun_write(int fd, char *buf, int len);
|
||||
int tun_read(int fd, char *buf, int len);
|
||||
const char *tun_last_error();
|
||||
}
|
||||
|
@ -1,19 +1,20 @@
|
||||
/*
|
||||
VTun - Virtual Tunnel over TCP/IP network.
|
||||
|
||||
Copyright (C) 1998-2000 Maxim Krasnyansky <max_mk@yahoo.com>
|
||||
|
||||
VTun has been derived from VPPP package by Maxim Krasnyansky.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
/*
|
||||
* Hans - IP over ICMP
|
||||
* Copyright (C) 2009 Friedrich Schöller <hans@schoeller.se>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "tunemu.h"
|
||||
@ -22,10 +23,7 @@
|
||||
|
||||
int tun_open(char *dev)
|
||||
{
|
||||
int fd = tunemu_open(dev);
|
||||
if (fd < 0)
|
||||
syslog(LOG_ERR, tunemu_error);
|
||||
return fd;
|
||||
return tunemu_open(dev);
|
||||
}
|
||||
|
||||
int tun_close(int fd, char *dev)
|
||||
@ -42,3 +40,8 @@ int tun_read(int fd, char *buf, int len)
|
||||
{
|
||||
return tunemu_read(fd, buf, len);
|
||||
}
|
||||
|
||||
const char *tun_last_error()
|
||||
{
|
||||
return tunemu_error;
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if_tun.h>
|
||||
@ -81,3 +82,8 @@ int tun_read(int fd, char *buf, int len)
|
||||
{
|
||||
return read(fd, buf, len);
|
||||
}
|
||||
|
||||
const char *tun_last_error()
|
||||
{
|
||||
return strerror(errno);
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* #include "vtun.h"
|
||||
#include "lib.h" */
|
||||
@ -72,3 +73,8 @@ int tun_read(int fd, char *buf, int len)
|
||||
{
|
||||
return read(fd, buf, len);
|
||||
}
|
||||
|
||||
const char *tun_last_error()
|
||||
{
|
||||
return strerror(errno);
|
||||
}
|
||||
|
@ -130,3 +130,8 @@ int tap_write(int fd, char *buf, int len) { return write(fd, buf, len); }
|
||||
|
||||
int tun_read(int fd, char *buf, int len) { return read(fd, buf, len); }
|
||||
int tap_read(int fd, char *buf, int len) { return read(fd, buf, len); }
|
||||
|
||||
const char *tun_last_error()
|
||||
{
|
||||
return strerror(errno);
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
@ -98,3 +99,8 @@ int tun_read(int fd, char *buf, int len)
|
||||
else
|
||||
return rlen;
|
||||
}
|
||||
|
||||
const char *tun_last_error()
|
||||
{
|
||||
return strerror(errno);
|
||||
}
|
||||
|
@ -175,3 +175,8 @@ int tun_read(int fd, char *buf, int len)
|
||||
sbuf.buf = buf;
|
||||
return getmsg(fd, NULL, &sbuf, &f) >=0 ? sbuf.len : -1;
|
||||
}
|
||||
|
||||
const char *tun_last_error()
|
||||
{
|
||||
return strerror(errno);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user