summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile3
-rw-r--r--src/anytunError.cpp53
-rw-r--r--src/anytunError.h (renamed from src/anytunError.hpp)30
-rw-r--r--src/authAlgo.cpp5
-rw-r--r--src/bsd/tunDevice.cpp6
-rw-r--r--src/cipher.cpp9
-rw-r--r--src/cryptinit.hpp4
-rw-r--r--src/daemon.hpp16
-rw-r--r--src/deviceConfig.hpp2
-rw-r--r--src/encryptedPacket.cpp2
-rw-r--r--src/keyDerivation.cpp11
-rw-r--r--src/linux/tunDevice.cpp8
-rw-r--r--src/log.cpp18
-rw-r--r--src/log.h24
-rw-r--r--src/logTargets.cpp2
-rw-r--r--src/networkAddress.cpp2
-rw-r--r--src/plainPacket.cpp2
-rw-r--r--src/routingTable.cpp2
-rw-r--r--src/routingTree.hpp2
-rw-r--r--src/signalController.cpp4
-rw-r--r--src/sysexec.hpp2
-rw-r--r--src/win32/registryKey.cpp6
-rw-r--r--src/win32/tunDevice.cpp26
-rw-r--r--src/win32/winService.cpp20
24 files changed, 151 insertions, 108 deletions
diff --git a/src/Makefile b/src/Makefile
index fa4c519..cde77c6 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -51,6 +51,7 @@ OBJS := tunDevice.o \
signalController.o \
log.o \
logTargets.o \
+ anytunError.o \
options.o \
seqWindow.o \
routingTreeNode.o \
@@ -68,11 +69,13 @@ ANYCTROBJS := signalController.o \
buffer.o \
log.o \
logTargets.o \
+ anytunError.o \
syncTcpConnection.o \
syncServer.o
ANYCONFOBJS := log.o \
logTargets.o \
+ anytunError.o \
buffer.o \
keyDerivation.o \
keyDerivationFactory.o \
diff --git a/src/anytunError.cpp b/src/anytunError.cpp
new file mode 100644
index 0000000..1a530a7
--- /dev/null
+++ b/src/anytunError.cpp
@@ -0,0 +1,53 @@
+/*
+ * anytun
+ *
+ * The secure anycast tunneling protocol (satp) defines a protocol used
+ * for communication between any combination of unicast and anycast
+ * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
+ * mode and allows tunneling of every ETHER TYPE protocol (e.g.
+ * ethernet, ip, arp ...). satp directly includes cryptography and
+ * message authentication based on the methodes used by SRTP. It is
+ * intended to deliver a generic, scaleable and secure solution for
+ * tunneling and relaying of packets of any protocol.
+ *
+ *
+ * Copyright (C) 2007-2008 Othmar Gsenger, Erwin Nindl,
+ * Christian Pointner <satp@wirdorange.org>
+ *
+ * This file is part of Anytun.
+ *
+ * Anytun is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Anytun 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 anytun. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "anytunError.h"
+
+#include <sstream>
+#include <boost/system/system_error.hpp>
+
+#ifndef NO_CRYPT
+#ifndef USE_SSL_CRYPTO
+std::ostream& operator<<(std::ostream& stream, AnytunGpgError const& value)
+{
+ char buf[STERROR_TEXT_MAX];
+ buf[0] = 0;
+ gpg_strerror_r(value.err_, buf, STERROR_TEXT_MAX);
+ return stream << buf;
+}
+#endif
+#endif
+
+std::ostream& operator<<(std::ostream& stream, AnytunErrno const& value)
+{
+ boost::system::system_error err(boost::system::error_code(value.err_, boost::system::get_system_category()));
+ return stream << err.what();
+}
diff --git a/src/anytunError.hpp b/src/anytunError.h
index 9a84277..26b4012 100644
--- a/src/anytunError.hpp
+++ b/src/anytunError.h
@@ -29,10 +29,36 @@
* along with anytun. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _ANYTUN_ERROR_HPP
-#define _ANYTUN_ERROR_HPP
+#ifndef _ANYTUN_ERROR_H
+#define _ANYTUN_ERROR_H
#include <sstream>
+#include <boost/system/system_error.hpp>
+#include "datatypes.h"
+
+#define STERROR_TEXT_MAX 200
+
+#ifndef NO_CRYPT
+#ifndef USE_SSL_CRYPTO
+#include <gcrypt.h>
+
+class AnytunGpgError
+{
+public:
+ AnytunGpgError(gcry_error_t e) : err_(e) {};
+ gcry_error_t err_;
+};
+std::ostream& operator<<(std::ostream& stream, AnytunGpgError const& value);
+#endif
+#endif
+
+class AnytunErrno
+{
+public:
+ AnytunErrno(system_error_t e) : err_(e) {};
+ system_error_t err_;
+};
+std::ostream& operator<<(std::ostream& stream, AnytunErrno const& value);
class ErrorStringBuilder
{
diff --git a/src/authAlgo.cpp b/src/authAlgo.cpp
index a4f88cc..2d4e157 100644
--- a/src/authAlgo.cpp
+++ b/src/authAlgo.cpp
@@ -31,6 +31,7 @@
#include "authAlgo.h"
#include "log.h"
+#include "anytunError.h"
#include "buffer.h"
#include "encryptedPacket.h"
@@ -89,7 +90,7 @@ void Sha1AuthAlgo::generate(KeyDerivation& kd, EncryptedPacket& packet)
#ifndef USE_SSL_CRYPTO
gcry_error_t err = gcry_md_setkey(handle_, key_.getBuf(), key_.getLength());
if(err) {
- cLog.msg(Log::PRIO_ERR) << "Sha1AuthAlgo::setKey: Failed to set hmac key: " << LogGpgError(err);
+ cLog.msg(Log::PRIO_ERR) << "Sha1AuthAlgo::setKey: Failed to set hmac key: " << AnytunGpgError(err);
return;
}
@@ -129,7 +130,7 @@ bool Sha1AuthAlgo::checkTag(KeyDerivation& kd, EncryptedPacket& packet)
#ifndef USE_SSL_CRYPTO
gcry_error_t err = gcry_md_setkey(handle_, key_.getBuf(), key_.getLength());
if(err) {
- cLog.msg(Log::PRIO_ERR) << "Sha1AuthAlgo::setKey: Failed to set hmac key: " << LogGpgError(err);
+ cLog.msg(Log::PRIO_ERR) << "Sha1AuthAlgo::setKey: Failed to set hmac key: " << AnytunGpgError(err);
return false;
}
diff --git a/src/bsd/tunDevice.cpp b/src/bsd/tunDevice.cpp
index eee78ca..5d2b152 100644
--- a/src/bsd/tunDevice.cpp
+++ b/src/bsd/tunDevice.cpp
@@ -47,7 +47,7 @@
#include "tunDevice.h"
#include "threadUtils.hpp"
#include "log.h"
-#include "anytunError.hpp"
+#include "anytunError.h"
#define DEVICE_FILE_MAX 255
@@ -95,7 +95,7 @@ TunDevice::TunDevice(std::string dev_name, std::string dev_type, std::string ifc
if(dynamic)
AnytunError::throwErr() << "can't open device file dynamically: no unused node left";
else
- AnytunError::throwErr() << "can't open device file (" << device_file << "): " << LogErrno(errno);
+ AnytunError::throwErr() << "can't open device file (" << device_file << "): " << AnytunErrno(errno);
}
if(dynamic) {
@@ -254,7 +254,7 @@ void TunDevice::do_ifconfig()
int result = system(command.str().c_str());
if(result == -1)
- cLog.msg(Log::PRIO_ERR) << "Execution of ifconfig failed" << LogErrno(errno);
+ cLog.msg(Log::PRIO_ERR) << "Execution of ifconfig failed" << AnytunErrno(errno);
else {
if(WIFEXITED(result))
cLog.msg(Log::PRIO_NOTICE) << "ifconfig returned " << WEXITSTATUS(result);
diff --git a/src/cipher.cpp b/src/cipher.cpp
index e14860c..52dd908 100644
--- a/src/cipher.cpp
+++ b/src/cipher.cpp
@@ -39,6 +39,7 @@
#include "cipher.h"
#include "log.h"
+#include "anytunError.h"
void Cipher::encrypt(KeyDerivation& kd, PlainPacket & in, EncryptedPacket & out, seq_nr_t seq_nr, sender_id_t sender_id, mux_t mux)
{
@@ -111,7 +112,7 @@ void AesIcmCipher::init(u_int16_t key_length)
gcry_error_t err = gcry_cipher_open(&handle_, algo, GCRY_CIPHER_MODE_CTR, 0);
if( err ) {
- cLog.msg(Log::PRIO_CRIT) << "AesIcmCipher::AesIcmCipher: Failed to open cipher" << LogGpgError(err);
+ cLog.msg(Log::PRIO_CRIT) << "AesIcmCipher::AesIcmCipher: Failed to open cipher" << AnytunGpgError(err);
}
#endif
}
@@ -173,7 +174,7 @@ void AesIcmCipher::calc(KeyDerivation& kd, u_int8_t* in, u_int32_t ilen, u_int8_
#else
gcry_error_t err = gcry_cipher_setkey(handle_, key_.getBuf(), key_.getLength());
if(err) {
- cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to set cipher key: " << LogGpgError(err);
+ cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to set cipher key: " << AnytunGpgError(err);
return;
}
#endif
@@ -183,13 +184,13 @@ void AesIcmCipher::calc(KeyDerivation& kd, u_int8_t* in, u_int32_t ilen, u_int8_
#ifndef USE_SSL_CRYPTO
err = gcry_cipher_setctr(handle_, ctr_.buf_, CTR_LENGTH);
if(err) {
- cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to set cipher CTR: " << LogGpgError(err);
+ cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to set cipher CTR: " << AnytunGpgError(err);
return;
}
err = gcry_cipher_encrypt(handle_, out, olen, in, ilen);
if(err) {
- cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to de/encrypt packet: " << LogGpgError(err);
+ cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to de/encrypt packet: " << AnytunGpgError(err);
return;
}
#else
diff --git a/src/cryptinit.hpp b/src/cryptinit.hpp
index 2caa4cb..4460de0 100644
--- a/src/cryptinit.hpp
+++ b/src/cryptinit.hpp
@@ -92,14 +92,14 @@ bool initLibGCrypt()
gcry_error_t err = gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
if( err ) {
- std::cout << "initLibGCrypt: Failed to disable secure memory: " << LogGpgError(err) << std::endl;
+ std::cout << "initLibGCrypt: Failed to disable secure memory: " << AnytunGpgError(err) << std::endl;
return false;
}
// Tell Libgcrypt that initialization has completed.
err = gcry_control(GCRYCTL_INITIALIZATION_FINISHED);
if( err ) {
- std::cout << "initLibGCrypt: Failed to finish initialization: " << LogGpgError(err) << std::endl;
+ std::cout << "initLibGCrypt: Failed to finish initialization: " << AnytunGpgError(err) << std::endl;
return false;
}
diff --git a/src/daemon.hpp b/src/daemon.hpp
index 992d354..7f0cf0b 100644
--- a/src/daemon.hpp
+++ b/src/daemon.hpp
@@ -42,7 +42,7 @@
#include <unistd.h>
#include "log.h"
-#include "anytunError.hpp"
+#include "anytunError.h"
#ifndef NO_PRIVDROP
class PrivInfo
@@ -75,15 +75,15 @@ public:
return;
if(setgid(gr_->gr_gid))
- AnytunError::throwErr() << "setgid('" << gr_->gr_name << "') failed: " << LogErrno(errno);
+ AnytunError::throwErr() << "setgid('" << gr_->gr_name << "') failed: " << AnytunErrno(errno);
gid_t gr_list[1];
gr_list[0] = gr_->gr_gid;
if(setgroups (1, gr_list))
- AnytunError::throwErr() << "setgroups(['" << gr_->gr_name << "']) failed: " << LogErrno(errno);
+ AnytunError::throwErr() << "setgroups(['" << gr_->gr_name << "']) failed: " << AnytunErrno(errno);
if(setuid(pw_->pw_uid))
- AnytunError::throwErr() << "setuid('" << pw_->pw_name << "') failed: " << LogErrno(errno);
+ AnytunError::throwErr() << "setuid('" << pw_->pw_name << "') failed: " << AnytunErrno(errno);
cLog.msg(Log::PRIO_NOTICE) << "dropped privileges to " << pw_->pw_name << ":" << gr_->gr_name;
}
@@ -113,23 +113,23 @@ void daemonize()
pid = fork();
if(pid < 0)
- AnytunError::throwErr() << "daemonizing failed at fork(): " << LogErrno(errno) << ", exitting";
+ AnytunError::throwErr() << "daemonizing failed at fork(): " << AnytunErrno(errno) << ", exitting";
if(pid) exit(0);
umask(0);
if(setsid() < 0)
- AnytunError::throwErr() << "daemonizing failed at setsid(): " << LogErrno(errno) << ", exitting";
+ AnytunError::throwErr() << "daemonizing failed at setsid(): " << AnytunErrno(errno) << ", exitting";
pid = fork();
if(pid < 0)
- AnytunError::throwErr() << "daemonizing failed at fork(): " << LogErrno(errno) << ", exitting";
+ AnytunError::throwErr() << "daemonizing failed at fork(): " << AnytunErrno(errno) << ", exitting";
if(pid) exit(0);
if ((chdir("/")) < 0)
- AnytunError::throwErr() << "daemonizing failed at chdir(): " << LogErrno(errno) << ", exitting";
+ AnytunError::throwErr() << "daemonizing failed at chdir(): " << AnytunErrno(errno) << ", exitting";
// std::cout << "running in background now..." << std::endl;
diff --git a/src/deviceConfig.hpp b/src/deviceConfig.hpp
index 515e38d..d8702b9 100644
--- a/src/deviceConfig.hpp
+++ b/src/deviceConfig.hpp
@@ -34,7 +34,7 @@
#include "networkAddress.h"
#include <boost/asio.hpp>
-#include "anytunError.hpp"
+#include "anytunError.h"
class TunDevice;
diff --git a/src/encryptedPacket.cpp b/src/encryptedPacket.cpp
index 34d2725..c18551c 100644
--- a/src/encryptedPacket.cpp
+++ b/src/encryptedPacket.cpp
@@ -37,7 +37,7 @@
#include "endian.h"
#include "datatypes.h"
#include "log.h"
-#include "anytunError.hpp"
+#include "anytunError.h"
EncryptedPacket::EncryptedPacket(u_int32_t payload_length, bool allow_realloc)
: Buffer(payload_length + sizeof(struct HeaderStruct), allow_realloc)
diff --git a/src/keyDerivation.cpp b/src/keyDerivation.cpp
index bfdef3f..c091ee6 100644
--- a/src/keyDerivation.cpp
+++ b/src/keyDerivation.cpp
@@ -31,6 +31,7 @@
#include "log.h"
+#include "anytunError.h"
#include "keyDerivation.h"
#include "threadUtils.hpp"
#include "datatypes.h"
@@ -225,13 +226,13 @@ void AesIcmKeyDerivation::updateMasterKey()
gcry_error_t err = gcry_cipher_open(&handle_[i], algo, GCRY_CIPHER_MODE_CTR, 0);
if(err) {
- cLog.msg(Log::PRIO_ERR) << "KeyDerivation::updateMasterKey: Failed to open cipher: " << LogGpgError(err);
+ cLog.msg(Log::PRIO_ERR) << "KeyDerivation::updateMasterKey: Failed to open cipher: " << AnytunGpgError(err);
return;
}
err = gcry_cipher_setkey(handle_[i], master_key_.getBuf(), master_key_.getLength());
if(err) {
- cLog.msg(Log::PRIO_ERR) << "KeyDerivation::updateMasterKey: Failed to set cipher key: " << LogGpgError(err);
+ cLog.msg(Log::PRIO_ERR) << "KeyDerivation::updateMasterKey: Failed to set cipher key: " << AnytunGpgError(err);
return;
}
}
@@ -309,19 +310,19 @@ bool AesIcmKeyDerivation::generate(kd_dir_t dir, satp_prf_label_t label, seq_nr_
#ifndef USE_SSL_CRYPTO
gcry_error_t err = gcry_cipher_reset(handle_[dir]);
if(err) {
- cLog.msg(Log::PRIO_ERR) << "KeyDerivation::generate: Failed to reset cipher: " << LogGpgError(err);
+ cLog.msg(Log::PRIO_ERR) << "KeyDerivation::generate: Failed to reset cipher: " << AnytunGpgError(err);
}
err = gcry_cipher_setctr(handle_[dir], ctr_[dir].buf_, CTR_LENGTH);
if(err) {
- cLog.msg(Log::PRIO_ERR) << "KeyDerivation::generate: Failed to set CTR: " << LogGpgError(err);
+ cLog.msg(Log::PRIO_ERR) << "KeyDerivation::generate: Failed to set CTR: " << AnytunGpgError(err);
return false;
}
std::memset(key.getBuf(), 0, key.getLength());
err = gcry_cipher_encrypt(handle_[dir], key, key.getLength(), NULL, 0);
if(err) {
- cLog.msg(Log::PRIO_ERR) << "KeyDerivation::generate: Failed to generate cipher bitstream: " << LogGpgError(err);
+ cLog.msg(Log::PRIO_ERR) << "KeyDerivation::generate: Failed to generate cipher bitstream: " << AnytunGpgError(err);
}
return true;
#else
diff --git a/src/linux/tunDevice.cpp b/src/linux/tunDevice.cpp
index 7c7e8ff..3f8e5bf 100644
--- a/src/linux/tunDevice.cpp
+++ b/src/linux/tunDevice.cpp
@@ -45,7 +45,7 @@
#include "tunDevice.h"
#include "threadUtils.hpp"
#include "log.h"
-#include "anytunError.hpp"
+#include "anytunError.h"
TunDevice::TunDevice(std::string dev_name, std::string dev_type, std::string ifcfg_addr, u_int16_t ifcfg_prefix) : conf_(dev_name, dev_type, ifcfg_addr, ifcfg_prefix, 1400)
{
@@ -68,7 +68,7 @@ TunDevice::TunDevice(std::string dev_name, std::string dev_type, std::string ifc
fd_ = ::open(DEFAULT_DEVICE, O_RDWR);
if(fd_ < 0)
- AnytunError::throwErr() << "can't open device file (" << DEFAULT_DEVICE << "): " << LogErrno(errno);
+ AnytunError::throwErr() << "can't open device file (" << DEFAULT_DEVICE << "): " << AnytunErrno(errno);
if(!ioctl(fd_, TUNSETIFF, &ifr)) {
actual_name_ = ifr.ifr_name;
@@ -76,7 +76,7 @@ TunDevice::TunDevice(std::string dev_name, std::string dev_type, std::string ifc
actual_name_ = ifr.ifr_name;
} else {
::close(fd_);
- AnytunError::throwErr() << "tun/tap device ioctl failed: " << LogErrno(errno);
+ AnytunError::throwErr() << "tun/tap device ioctl failed: " << AnytunErrno(errno);
}
actual_node_ = DEFAULT_DEVICE;
@@ -161,7 +161,7 @@ void TunDevice::do_ifconfig()
int result = system(command.str().c_str());
if(result == -1)
- cLog.msg(Log::PRIO_ERR) << "Execution of ifconfig failed: " << LogErrno(errno);
+ cLog.msg(Log::PRIO_ERR) << "Execution of ifconfig failed: " << AnytunErrno(errno);
else {
if(WIFEXITED(result))
cLog.msg(Log::PRIO_NOTICE) << "ifconfig returned " << WEXITSTATUS(result);
diff --git a/src/log.cpp b/src/log.cpp
index f99ee78..aa2c68d 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -31,7 +31,6 @@
#include <iostream>
#include <string>
-#include <boost/system/system_error.hpp>
#include "log.h"
#include "threadUtils.hpp"
@@ -40,23 +39,6 @@ Log* Log::inst = NULL;
Mutex Log::instMutex;
Log& cLog = Log::instance();
-#ifndef NO_CRYPT
-#ifndef USE_SSL_CRYPTO
-std::ostream& operator<<(std::ostream& stream, LogGpgError const& value)
-{
- char buf[STERROR_TEXT_MAX];
- buf[0] = 0;
- gpg_strerror_r(value.err_, buf, STERROR_TEXT_MAX);
- return stream << buf;
-}
-#endif
-#endif
-std::ostream& operator<<(std::ostream& stream, LogErrno const& value)
-{
- boost::system::system_error err(boost::system::error_code(value.err_,boost::system::get_system_category()));
- return stream << err.what();
-}
-
LogStringBuilder::LogStringBuilder(LogStringBuilder const& src) : log(src.log), prio(src.prio)
{
stream << src.stream.str();
diff --git a/src/log.h b/src/log.h
index 56ca5ae..cd83e84 100644
--- a/src/log.h
+++ b/src/log.h
@@ -43,30 +43,6 @@
#include "threadUtils.hpp"
-#define STERROR_TEXT_MAX 200
-
-#ifndef NO_CRYPT
-#ifndef USE_SSL_CRYPTO
-#include <gcrypt.h>
-
-class LogGpgError
-{
-public:
- LogGpgError(gcry_error_t e) : err_(e) {};
- gcry_error_t err_;
-};
-std::ostream& operator<<(std::ostream& stream, LogGpgError const& value);
-#endif
-#endif
-
-class LogErrno
-{
-public:
- LogErrno(system_error_t e) : err_(e) {};
- system_error_t err_;
-};
-std::ostream& operator<<(std::ostream& stream, LogErrno const& value);
-
class Log;
class LogStringBuilder
diff --git a/src/logTargets.cpp b/src/logTargets.cpp
index d22734d..752ba29 100644
--- a/src/logTargets.cpp
+++ b/src/logTargets.cpp
@@ -35,7 +35,7 @@
#include "logTargets.h"
#include "log.h"
-#include "anytunError.hpp"
+#include "anytunError.h"
#include "options.h"
diff --git a/src/networkAddress.cpp b/src/networkAddress.cpp
index 99da84b..61c8318 100644
--- a/src/networkAddress.cpp
+++ b/src/networkAddress.cpp
@@ -34,7 +34,7 @@
#include <exception>
#include "networkAddress.h"
-#include "anytunError.hpp"
+#include "anytunError.h"
NetworkAddress::NetworkAddress():ipv4_address_(),ipv6_address_()
{
diff --git a/src/plainPacket.cpp b/src/plainPacket.cpp
index f3f9a8d..9c39b63 100644
--- a/src/plainPacket.cpp
+++ b/src/plainPacket.cpp
@@ -34,7 +34,7 @@
#include "datatypes.h"
#include "endian.h"
#include "plainPacket.h"
-#include "anytunError.hpp"
+#include "anytunError.h"
PlainPacket::PlainPacket(u_int32_t payload_length, bool allow_realloc) : Buffer(payload_length + sizeof(payload_type_t), allow_realloc)
{
diff --git a/src/routingTable.cpp b/src/routingTable.cpp
index f20983b..b683dca 100644
--- a/src/routingTable.cpp
+++ b/src/routingTable.cpp
@@ -31,7 +31,7 @@
#include "networkPrefix.h"
#include "threadUtils.hpp"
#include "datatypes.h"
-#include "anytunError.hpp"
+#include "anytunError.h"
#include "routingTable.h"
#include "routingTree.hpp"
diff --git a/src/routingTree.hpp b/src/routingTree.hpp
index 645b84d..3a9024d 100644
--- a/src/routingTree.hpp
+++ b/src/routingTree.hpp
@@ -32,7 +32,7 @@
#ifndef __ROUTING_TREE_
#define __ROUTING_TREE_
-#include "anytunError.hpp"
+#include "anytunError.h"
class RoutingTree {
diff --git a/src/signalController.cpp b/src/signalController.cpp
index 266ef96..39748c2 100644
--- a/src/signalController.cpp
+++ b/src/signalController.cpp
@@ -36,7 +36,7 @@
#include "signalController.h"
#include "log.h"
-#include "anytunError.hpp"
+#include "anytunError.h"
#include "threadUtils.hpp"
#ifndef _MSC_VER
@@ -204,7 +204,7 @@ void SignalController::init()
handler[SIGUSR2] = new SigUsr2Handler;
#else
if(!SetConsoleCtrlHandler((PHANDLER_ROUTINE)SignalController::handle, true))
- AnytunError::throwErr() << "Error on SetConsoleCtrlhandler: " << LogErrno(GetLastError());
+ AnytunError::throwErr() << "Error on SetConsoleCtrlhandler: " << AnytunErrno(GetLastError());
handler[CTRL_C_EVENT] = new CtrlCHandler;
handler[CTRL_BREAK_EVENT] = new CtrlBreakHandler;
diff --git a/src/sysexec.hpp b/src/sysexec.hpp
index 0730cea..9de28ec 100644
--- a/src/sysexec.hpp
+++ b/src/sysexec.hpp
@@ -53,7 +53,7 @@ int execScript(std::string const& script, std::string const& ifname, std::string
}
execl("/bin/sh", "/bin/sh", script.c_str(), ifname.c_str(), ifnode.c_str(), (char*)NULL);
// if execl return, an error occurred
- cLog.msg(Log::PRIO_ERR) << "error on executing script: " << LogErrno(errno);
+ cLog.msg(Log::PRIO_ERR) << "error on executing script: " << AnytunErrno(errno);
return -1;
}
int status = 0;
diff --git a/src/win32/registryKey.cpp b/src/win32/registryKey.cpp
index 4ce92b9..9f4b653 100644
--- a/src/win32/registryKey.cpp
+++ b/src/win32/registryKey.cpp
@@ -87,19 +87,19 @@ void RegistryKey::close()
std::string RegistryKey::operator[](std::string const& name) const
{
if(!opened_)
- throw LogErrno(ERROR_INVALID_HANDLE);
+ throw AnytunErrno(ERROR_INVALID_HANDLE);
char value[STRING_VALUE_LENGTH];
DWORD len = sizeof(value);
LONG err = RegQueryValueExA(key_, name.c_str(), NULL, NULL, (LPBYTE)value, &len);
if(err != ERROR_SUCCESS)
- throw LogErrno(err);
+ throw AnytunErrno(err);
if(value[len-1] != 0) {
if(len < sizeof(value))
value[len++] = 0;
else
- throw LogErrno(ERROR_INSUFFICIENT_BUFFER);
+ throw AnytunErrno(ERROR_INSUFFICIENT_BUFFER);
}
return std::string(value);
}
diff --git a/src/win32/tunDevice.cpp b/src/win32/tunDevice.cpp
index 9761997..f9b9092 100644
--- a/src/win32/tunDevice.cpp
+++ b/src/win32/tunDevice.cpp
@@ -38,7 +38,7 @@
#include "../tunDevice.h"
#include "../threadUtils.hpp"
#include "../log.h"
-#include "../anytunError.hpp"
+#include "../anytunError.h"
#include "registryKey.h"
#include "common.h"
@@ -60,7 +60,7 @@ TunDevice::TunDevice(std::string dev_name, std::string dev_type, std::string ifc
tapname << USERMODEDEVICEDIR << actual_node_ << TAPSUFFIX;
handle_ = CreateFileA(tapname.str().c_str(), GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 0);
if(handle_ == INVALID_HANDLE_VALUE)
- AnytunError::throwErr() << "Unable to open device: " << actual_node_ << " (" << actual_name_ << "): " << LogErrno(GetLastError());
+ AnytunError::throwErr() << "Unable to open device: " << actual_node_ << " (" << actual_name_ << "): " << AnytunErrno(GetLastError());
}
DWORD err;
@@ -69,7 +69,7 @@ TunDevice::TunDevice(std::string dev_name, std::string dev_type, std::string ifc
err = performIoControl(TAP_IOCTL_GET_VERSION, info, sizeof(info), info, sizeof(info));
if(err != ERROR_SUCCESS) {
CloseHandle(handle_);
- AnytunError::throwErr() << "Unable to get device version: " << LogErrno(err);
+ AnytunError::throwErr() << "Unable to get device version: " << AnytunErrno(err);
}
cLog.msg(Log::PRIO_NOTICE) << "Windows TAP Driver Version " << info[0] << "." << info[1] << " " << (info[2] ? "(DEBUG)" : "");
if(!(info[0] > MIN_TAP_VER_MAJOR || (info[0] == MIN_TAP_VER_MAJOR && info[1] >= MIN_TAP_VER_MINOR))) {
@@ -85,7 +85,7 @@ TunDevice::TunDevice(std::string dev_name, std::string dev_type, std::string ifc
err = performIoControl(TAP_IOCTL_CONFIG_TUN, ep, sizeof(ep), ep, sizeof(ep));
if(err != ERROR_SUCCESS) {
CloseHandle(handle_);
- AnytunError::throwErr() << "Unable to set device tun mode: " << LogErrno(err);
+ AnytunError::throwErr() << "Unable to set device tun mode: " << AnytunErrno(err);
}
}
@@ -96,7 +96,7 @@ TunDevice::TunDevice(std::string dev_name, std::string dev_type, std::string ifc
err = performIoControl(TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof(status), &status, sizeof(status));
if(err != ERROR_SUCCESS) {
CloseHandle(handle_);
- AnytunError::throwErr() << "Unable to set device media status: " << LogErrno(err);
+ AnytunError::throwErr() << "Unable to set device media status: " << AnytunErrno(err);
}
roverlapped_.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
@@ -108,7 +108,7 @@ bool TunDevice::getAdapter(std::string const& dev_name)
RegistryKey akey;
DWORD err = akey.open(HKEY_LOCAL_MACHINE, ADAPTER_KEY, KEY_ENUMERATE_SUB_KEYS);
if(err != ERROR_SUCCESS)
- AnytunError::throwErr() << "Unable to open registry key (HKLM\\" << ADAPTER_KEY << "): " << LogErrno(err);
+ AnytunError::throwErr() << "Unable to open registry key (HKLM\\" << ADAPTER_KEY << "): " << AnytunErrno(err);
bool found = false;
for(int i=0; ; ++i) {
@@ -132,7 +132,7 @@ bool TunDevice::getAdapter(std::string const& dev_name)
continue;
actual_name_ = nkey["Name"];
- } catch(LogErrno& e) { continue; }
+ } catch(AnytunErrno& e) { continue; }
if(dev_name != "") {
if(dev_name == actual_name_) {
@@ -207,12 +207,12 @@ int TunDevice::read(u_int8_t* buf, u_int32_t len)
if(err == ERROR_IO_PENDING) {
WaitForSingleObject(roverlapped_.hEvent, INFINITE);
if(!GetOverlappedResult(handle_, &roverlapped_, &lenout, FALSE)) {
- cLog.msg(Log::PRIO_ERR) << "Error while trying to get overlapped result: " << LogErrno(GetLastError());
+ cLog.msg(Log::PRIO_ERR) << "Error while trying to get overlapped result: " << AnytunErrno(GetLastError());
return -1;
}
}
else {
- cLog.msg(Log::PRIO_ERR) << "Error while reading from device: " << LogErrno(GetLastError());
+ cLog.msg(Log::PRIO_ERR) << "Error while reading from device: " << AnytunErrno(GetLastError());
return -1;
}
}
@@ -231,12 +231,12 @@ int TunDevice::write(u_int8_t* buf, u_int32_t len)
if(err == ERROR_IO_PENDING) {
WaitForSingleObject(woverlapped_.hEvent, INFINITE);
if(!GetOverlappedResult(handle_, &woverlapped_, &lenout, FALSE)) {
- cLog.msg(Log::PRIO_ERR) << "Error while trying to get overlapped result: " << LogErrno(GetLastError());
+ cLog.msg(Log::PRIO_ERR) << "Error while trying to get overlapped result: " << AnytunErrno(GetLastError());
return -1;
}
}
else {
- cLog.msg(Log::PRIO_ERR) << "Error while writing to device: " << LogErrno(GetLastError());
+ cLog.msg(Log::PRIO_ERR) << "Error while writing to device: " << AnytunErrno(GetLastError());
return -1;
}
}
@@ -258,14 +258,14 @@ void TunDevice::do_ifconfig()
DWORD err = performIoControl(TAP_IOCTL_CONFIG_DHCP_MASQ, ep, sizeof(ep), ep, sizeof(ep));
if(err != ERROR_SUCCESS) {
CloseHandle(handle_);
- AnytunError::throwErr() << "Unable to set device dhcp masq mode: " << LogErrno(err);
+ AnytunError::throwErr() << "Unable to set device dhcp masq mode: " << AnytunErrno(err);
}
u_long mtu;
err = performIoControl(TAP_IOCTL_GET_MTU, &mtu, sizeof(mtu), &mtu, sizeof(mtu));
if(err != ERROR_SUCCESS) {
CloseHandle(handle_);
- AnytunError::throwErr() << "Unable to get device mtu: " << LogErrno(err);
+ AnytunError::throwErr() << "Unable to get device mtu: " << AnytunErrno(err);
}
conf_.mtu_ = static_cast<u_int16_t>(mtu);
}
diff --git a/src/win32/winService.cpp b/src/win32/winService.cpp
index 58ad3ca..fefa725 100644
--- a/src/win32/winService.cpp
+++ b/src/win32/winService.cpp
@@ -37,7 +37,7 @@
#include "winService.h"
#include "../log.h"
-#include "../anytunError.hpp"
+#include "../anytunError.h"
#include "../threadUtils.hpp"
WinService* WinService::inst = NULL;
@@ -67,17 +67,17 @@ void WinService::install()
char szPath[MAX_PATH];
if(!GetModuleFileNameA(NULL, szPath, MAX_PATH))
- AnytunError::throwErr() << "Error on GetModuleFileName: " << LogErrno(GetLastError());
+ AnytunError::throwErr() << "Error on GetModuleFileName: " << AnytunErrno(GetLastError());
schSCManager = OpenSCManagerA(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if(NULL == schSCManager)
- AnytunError::throwErr() << "Error on OpenSCManager: " << LogErrno(GetLastError());
+ AnytunError::throwErr() << "Error on OpenSCManager: " << AnytunErrno(GetLastError());
schService = CreateServiceA(schSCManager, SVC_NAME, SVC_NAME, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, szPath, NULL, NULL, NULL, NULL, NULL);
if(schService == NULL) {
CloseServiceHandle(schSCManager);
- AnytunError::throwErr() << "Error on CreateService: " << LogErrno(GetLastError());
+ AnytunError::throwErr() << "Error on CreateService: " << AnytunErrno(GetLastError());
}
std::cout << "Service installed successfully" << std::endl;
@@ -93,18 +93,18 @@ void WinService::uninstall()
schSCManager = OpenSCManagerA(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if(NULL == schSCManager)
- AnytunError::throwErr() << "Error on OpenSCManager: " << LogErrno(GetLastError());
+ AnytunError::throwErr() << "Error on OpenSCManager: " << AnytunErrno(GetLastError());
schService = OpenServiceA(schSCManager, SVC_NAME, SERVICE_ALL_ACCESS);
if(schService == NULL) {
CloseServiceHandle(schSCManager);
- AnytunError::throwErr() << "Error on CreateService: " << LogErrno(GetLastError());
+ AnytunError::throwErr() << "Error on CreateService: " << AnytunErrno(GetLastError());
}
if(!DeleteService(schService)) {
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
- AnytunError::throwErr() << "Error on DeleteService: " << LogErrno(GetLastError());
+ AnytunError::throwErr() << "Error on DeleteService: " << AnytunErrno(GetLastError());
}
std::cout << "Service uninstalled successfully" << std::endl;
@@ -121,7 +121,7 @@ void WinService::start()
};
if(!StartServiceCtrlDispatcherA(DispatchTable))
- AnytunError::throwErr() << "Error on StartServiceCtrlDispatcher: " << LogErrno(GetLastError());
+ AnytunError::throwErr() << "Error on StartServiceCtrlDispatcher: " << AnytunErrno(GetLastError());
}
void WinService::waitForStop()
@@ -153,7 +153,7 @@ VOID WINAPI WinService::main(DWORD dwArgc, LPTSTR *lpszArgv)
gWinService.status_handle_ = RegisterServiceCtrlHandlerA(SVC_NAME, WinService::ctrlHandler);
if(!gWinService.status_handle_) {
- cLog.msg(Log::PRIO_ERR) << "Error on RegisterServiceCtrlHandler: " << LogErrno(GetLastError());
+ cLog.msg(Log::PRIO_ERR) << "Error on RegisterServiceCtrlHandler: " << AnytunErrno(GetLastError());
return;
}
gWinService.status_.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
@@ -163,7 +163,7 @@ VOID WINAPI WinService::main(DWORD dwArgc, LPTSTR *lpszArgv)
gWinService.stop_event_ = CreateEvent(NULL, true, false, NULL);
if(!gWinService.stop_event_) {
- cLog.msg(Log::PRIO_ERR) << "WinService Error on CreateEvent: " << LogErrno(GetLastError());
+ cLog.msg(Log::PRIO_ERR) << "WinService Error on CreateEvent: " << AnytunErrno(GetLastError());
gWinService.reportStatus(SERVICE_STOPPED, -1);
return;
}