From e1199f77266b0198457f08f58769795cff3eb2b9 Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Tue, 4 Sep 2007 17:21:25 +0000 Subject: added parameter type --- anytun.cpp | 2 +- options.cpp | 19 ++++++++++++++++++- options.h | 3 +++ tunDevice.cpp | 4 ++-- tunDevice.h | 2 +- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/anytun.cpp b/anytun.cpp index 82a40bf..d754adb 100644 --- a/anytun.cpp +++ b/anytun.cpp @@ -183,7 +183,7 @@ int main(int argc, char* argv[]) SignalController sig; sig.init(); - TunDevice dev(opt.getDevName().c_str(), opt.getIfconfigParamLocal().c_str(), opt.getIfconfigParamRemoteNetmask().c_str()); + TunDevice dev(opt.getDevName().c_str(),opt.getDevType().c_str(), opt.getIfconfigParamLocal().c_str(), opt.getIfconfigParamRemoteNetmask().c_str()); SeqWindow seq(opt.getSeqWindowSize()); uint8_t key[] = { diff --git a/options.cpp b/options.cpp index 9d97c51..b28100b 100644 --- a/options.cpp +++ b/options.cpp @@ -80,6 +80,7 @@ Options::Options() remote_addr_ = ""; remote_port_ = 4444; dev_name_ = "tap"; + dev_type_ = ""; ifconfig_param_local_ = "192.168.200.1"; ifconfig_param_remote_netmask_ = "255.255.255.0"; seq_window_size_ = 100; @@ -107,6 +108,7 @@ bool Options::parse(int argc, char* argv[]) PARSE_SCALAR_PARAM("-r","--remote-host", remote_addr_) PARSE_SCALAR_PARAM("-o","--remote-port", remote_port_) PARSE_SCALAR_PARAM("-d","--dev", dev_name_) + PARSE_SCALAR_PARAM("-t","--type", dev_type_) PARSE_SCALAR_PARAM2("-n","--ifconfig", ifconfig_param_local_, ifconfig_param_remote_netmask_) PARSE_SCALAR_PARAM("-w","--window-size", seq_window_size_) PARSE_SCALAR_PARAM("-c","--cypher", cypher_) @@ -127,7 +129,8 @@ void Options::printUsage() std::cout << " [-p|--port] local port to bind to" << std::endl; std::cout << " [-r|--remote-host] remote host" << std::endl; std::cout << " [-o|--remote-port] remote port" << std::endl; - std::cout << " [-d|--dev] device name/type" << std::endl; + std::cout << " [-d|--dev] device name" << std::endl; + std::cout << " [-t|--type] device type" << std::endl; std::cout << " [-n|--ifconfig] the local address for the tun/tap device" << std::endl << " the remote address(tun) or netmask(tap)" << std::endl; std::cout << " [-w|--window-size] seqence number window size" << std::endl; @@ -145,6 +148,7 @@ void Options::printOptions() std::cout << "remote_addr='" << remote_addr_ << "'" << std::endl; std::cout << "remote_port='" << remote_port_ << "'" << std::endl; std::cout << "dev_name='" << dev_name_ << "'" << std::endl; + std::cout << "dev_type='" << dev_type_ << "'" << std::endl; std::cout << "ifconfig_param_local='" << ifconfig_param_local_ << "'" << std::endl; std::cout << "ifconfig_param_remote_netmask='" << ifconfig_param_remote_netmask_ << "'" << std::endl; std::cout << "seq_window_size='" << seq_window_size_ << "'" << std::endl; @@ -238,6 +242,12 @@ std::string Options::getDevName() return dev_name_; } +std::string Options::getDevType() +{ + Lock lock(mutex); + return dev_type_; +} + Options& Options::setDevName(std::string d) { Lock lock(mutex); @@ -245,6 +255,13 @@ Options& Options::setDevName(std::string d) return *this; } +Options& Options::setDevType(std::string d) +{ + Lock lock(mutex); + dev_type_ = d; + return *this; +} + std::string Options::getIfconfigParamLocal() { Lock lock(mutex); diff --git a/options.h b/options.h index c73c47a..23b9824 100644 --- a/options.h +++ b/options.h @@ -56,6 +56,8 @@ public: Options& setRemoteAddrPort(std::string addr, u_int16_t port); std::string getDevName(); Options& setDevName(std::string d); + std::string getDevType(); + Options& setDevType(std::string d); std::string getIfconfigParamLocal(); Options& setIfconfigParamLocal(std::string i); std::string getIfconfigParamRemoteNetmask(); @@ -77,6 +79,7 @@ private: std::string remote_addr_; u_int16_t remote_port_; std::string dev_name_; + std::string dev_type_; std::string ifconfig_param_local_; std::string ifconfig_param_remote_netmask_; window_size_t seq_window_size_; diff --git a/tunDevice.cpp b/tunDevice.cpp index 8898c7f..40d0f9d 100644 --- a/tunDevice.cpp +++ b/tunDevice.cpp @@ -41,7 +41,7 @@ extern "C" { #include "threadUtils.hpp" -TunDevice::TunDevice(const char* dev_name, const char* ifcfg_lp, const char* ifcfg_rnmp) +TunDevice::TunDevice(const char* dev_name,const char* dev_type, const char* ifcfg_lp, const char* ifcfg_rnmp) { dev_ = NULL; @@ -92,7 +92,7 @@ TunDevice::TunDevice(const char* dev_name, const char* ifcfg_lp, const char* ifc // lp = inet_addr("192.168.198.1"); // rp = inet_addr("192.168.199.1"); - dev_ = init_tun(dev_name, NULL, ifcfg_lp, ifcfg_rnmp, lp, rp, 0, NULL); + dev_ = init_tun(dev_name, dev_type, ifcfg_lp, ifcfg_rnmp, lp, rp, 0, NULL); struct frame frame; // just for win32 struct tuntap_options options; // win32 & linux options.txqueuelen = 100; // just for linux diff --git a/tunDevice.h b/tunDevice.h index 8d6e9bd..8be2050 100644 --- a/tunDevice.h +++ b/tunDevice.h @@ -41,7 +41,7 @@ public: static const u_int32_t TYPE_TUN = 1; static const u_int32_t TYPE_TAP = 2; - TunDevice(const char* dev, const char* ifcfg_lp, const char* ifcfg_rnmp); + TunDevice(const char* dev,const char* dev_type, const char* ifcfg_lp, const char* ifcfg_rnmp); ~TunDevice(); void open(); -- cgit v1.2.3