From f5afa7efbc1ff915e733e8d1474777de80534345 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 26 Nov 2008 10:47:14 +0000 Subject: cleaned tunDevice code --- src/bsd/tunDevice.cpp | 48 ++++++++++--------------------------- src/bsd/tunDevice.h | 66 --------------------------------------------------- 2 files changed, 12 insertions(+), 102 deletions(-) delete mode 100644 src/bsd/tunDevice.h (limited to 'src/bsd') diff --git a/src/bsd/tunDevice.cpp b/src/bsd/tunDevice.cpp index 0ef1974..31e986c 100644 --- a/src/bsd/tunDevice.cpp +++ b/src/bsd/tunDevice.cpp @@ -50,11 +50,11 @@ #include -TunDevice::TunDevice(const char* dev_name, const char* dev_type, const char* ifcfg_lp, const char* ifcfg_rnmp) : conf_(dev_name, dev_type, ifcfg_lp, ifcfg_rnmp, 1400) +TunDevice::TunDevice(std::string dev_name, std::string dev_type, std::string ifcfg_lp, std::string ifcfg_rnmp) : conf_(dev_name, dev_type, ifcfg_lp, ifcfg_rnmp, 1400) { std::string device_file = "/dev/"; bool dynamic = true; - if(dev_name) { + if(dev_name != "") { device_file.append(dev_name); dynamic = false; } @@ -110,7 +110,7 @@ TunDevice::TunDevice(const char* dev_name, const char* dev_type, const char* ifc init_post(); - if(ifcfg_lp && ifcfg_rnmp) + if(ifcfg_lp != "" && ifcfg_rnmp != "") do_ifconfig(); } @@ -124,9 +124,9 @@ TunDevice::~TunDevice() void TunDevice::init_post() { - with_type_ = true; + with_pi_ = true; if(conf_.type_ == TYPE_TAP) - with_type_ = false; + with_pi_ = false; struct tuninfo ti; @@ -143,9 +143,9 @@ void TunDevice::init_post() void TunDevice::init_post() { - with_type_ = true; + with_pi_ = true; if(conf_.type_ == TYPE_TAP) - with_type_ = false; + with_pi_ = false; int arg = 0; ioctl(fd_, TUNSLMODE, &arg); @@ -157,7 +157,7 @@ void TunDevice::init_post() void TunDevice::init_post() { - with_type_ = false; + with_pi_ = false; int arg = IFF_POINTOPOINT|IFF_MULTICAST; ioctl(fd_, TUNSIFMODE, &arg); @@ -169,7 +169,7 @@ void TunDevice::init_post() #error This Device works just for OpenBSD, FreeBSD or NetBSD #endif -int TunDevice::fix_return(int ret, size_t type_length) +int TunDevice::fix_return(int ret, size_t pi_length) { if(ret < 0) return ret; @@ -177,12 +177,12 @@ int TunDevice::fix_return(int ret, size_t type_length) return (static_cast(ret) > type_length ? (ret - type_length) : 0); } -short TunDevice::read(u_int8_t* buf, u_int32_t len) +int TunDevice::read(u_int8_t* buf, u_int32_t len) { if(fd_ < 0) return -1; - if(with_type_) { + if(with_pi_) { struct iovec iov[2]; u_int32_t type; @@ -201,7 +201,7 @@ int TunDevice::write(u_int8_t* buf, u_int32_t len) if(fd_ < 0) return -1; - if(with_type_) { + if(with_pi_) { struct iovec iov[2]; u_int32_t type; struct ip *hdr = reinterpret_cast(buf); @@ -222,30 +222,6 @@ int TunDevice::write(u_int8_t* buf, u_int32_t len) return(::write(fd_, buf, len)); } -const char* TunDevice::getActualName() -{ - return actual_name_.c_str(); -} - -device_type_t TunDevice::getType() -{ - return conf_.type_; -} - -const char* TunDevice::getTypeString() -{ - if(fd_ < 0) - return NULL; - - switch(conf_.type_) - { - case TYPE_UNDEF: return "undef"; break; - case TYPE_TUN: return "tun"; break; - case TYPE_TAP: return "tap"; break; - } - return NULL; -} - void TunDevice::do_ifconfig() { std::ostringstream command; diff --git a/src/bsd/tunDevice.h b/src/bsd/tunDevice.h deleted file mode 100644 index 1d1c08e..0000000 --- a/src/bsd/tunDevice.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 - * - * 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 . - */ - -#ifndef _TUNDEVICE_H_ -#define _TUNDEVICE_H_ - -#include "buffer.h" -#include "deviceConfig.hpp" -#include "threadUtils.hpp" - -class TunDevice -{ -public: - TunDevice(const char* dev,const char* dev_type, const char* ifcfg_lp, const char* ifcfg_rnmp); - ~TunDevice(); - - short read(u_int8_t* buf, u_int32_t len); - int write(u_int8_t* buf, u_int32_t len); - - const char* getActualName(); - device_type_t getType(); - const char* getTypeString(); - -private: - void operator=(const TunDevice &src); - TunDevice(const TunDevice &src); - - void init_post(); - void do_ifconfig(); - int fix_return(int ret, size_t type_length); - - int fd_; - DeviceConfig conf_; - bool with_type_; - std::string actual_name_; -}; - -#endif -- cgit v1.2.3