diff options
author | Christian Pointner <equinox@anytun.org> | 2008-05-10 00:34:07 +0000 |
---|---|---|
committer | Christian Pointner <equinox@anytun.org> | 2008-05-10 00:34:07 +0000 |
commit | 18626031a3cbaeb470dba1d81adee2f6cd5cfd7d (patch) | |
tree | 2cea0f5af3cd692cc634cf2d5f147d99608d4525 /src | |
parent | small cleanup (diff) |
do_ifconfig works now for new tun/tap device
Diffstat (limited to 'src')
-rw-r--r-- | src/anytun.cpp | 20 | ||||
-rw-r--r-- | src/deviceConfig.hpp | 9 | ||||
-rw-r--r-- | src/linux/tunDevice.cpp | 22 | ||||
-rw-r--r-- | src/linux/tunDevice.h | 2 |
4 files changed, 40 insertions, 13 deletions
diff --git a/src/anytun.cpp b/src/anytun.cpp index e10d6fb..004330b 100644 --- a/src/anytun.cpp +++ b/src/anytun.cpp @@ -456,16 +456,16 @@ int main(int argc, char* argv[]) } - Buffer buff(u_int32_t(1600)); - int len; - while(1) - { - len = dev.read(buff.getBuf(), buff.getLength()); - std::cout << "read " << len << " bytes form interface " << dev.getActualName() << std::endl; - dev.write(buff.getBuf(), len); - } - - exit(0); +// Buffer buff(u_int32_t(1600)); +// int len; +// while(1) +// { +// len = dev.read(buff.getBuf(), buff.getLength()); +// std::cout << "read " << len << " bytes form interface " << dev.getActualName() << std::endl; +// dev.write(buff.getBuf(), len); +// } + +// exit(0); diff --git a/src/deviceConfig.hpp b/src/deviceConfig.hpp index caa6913..8b534aa 100644 --- a/src/deviceConfig.hpp +++ b/src/deviceConfig.hpp @@ -39,9 +39,7 @@ enum device_type_t { TYPE_UNDEF, TYPE_TUN, TYPE_TAP }; class DeviceConfig { public: - DeviceConfig(const char* dev_name ,const char* dev_type, - const char* ifcfg_lp, const char* ifcfg_rnmp) : local_(ipv4, ifcfg_lp), - remote_netmask_(ipv4, ifcfg_rnmp) + DeviceConfig(const char* dev_name ,const char* dev_type, const char* ifcfg_lp, const char* ifcfg_rnmp) { type_ = TYPE_UNDEF; if(dev_type) { @@ -56,6 +54,11 @@ public: else if(!strncmp(dev_name, "tap", 3)) type_ = TYPE_TAP; } + + if(ifcfg_lp) + local_.setNetworkAddress(ipv4, ifcfg_lp); + if(ifcfg_rnmp) + remote_netmask_.setNetworkAddress(ipv4, ifcfg_rnmp); } private: diff --git a/src/linux/tunDevice.cpp b/src/linux/tunDevice.cpp index 446df4f..8548331 100644 --- a/src/linux/tunDevice.cpp +++ b/src/linux/tunDevice.cpp @@ -77,6 +77,9 @@ TunDevice::TunDevice(const char* dev_name, const char* dev_type, const char* ifc msg.append(strerror(errno)); throw std::runtime_error(msg); } + + if(ifcfg_lp && ifcfg_rnmp) + do_ifconfig(); } TunDevice::~TunDevice() @@ -155,3 +158,22 @@ const char* TunDevice::getTypeString() } return NULL; } + +void TunDevice::do_ifconfig() +{ + std::string command("/sbin/ifconfig "); + command.append(actual_name_); + command.append(" "); + command.append(conf_.local_.toString()); + command.append(" "); + + if(conf_.type_ == TYPE_TUN) + command.append("pointopoint "); + else + command.append("netmask "); + + command.append(conf_.remote_netmask_.toString()); + command.append(" mtu 1400"); + + system(command.c_str()); +} diff --git a/src/linux/tunDevice.h b/src/linux/tunDevice.h index 9f3557a..d838dfc 100644 --- a/src/linux/tunDevice.h +++ b/src/linux/tunDevice.h @@ -52,6 +52,8 @@ private: void operator=(const TunDevice &src); TunDevice(const TunDevice &src); + void do_ifconfig(); + int fd_; DeviceConfig conf_; bool with_pi_; |