X-Git-Url: https://git.syn-net.org/debian/?a=blobdiff_plain;f=src%2Flinux%2FtunDevice.cpp;h=ee6ac0efdf27a17c86045ba4600bb0b534ef6c8f;hb=bf2cb4e3379948d1f2e65f2a6373cf0f8c379481;hp=b34ae9db46849fe666608904fe9de9fec7b86307;hpb=058ae090a970436caec3b3059e9e18b310dd6b0d;p=anytun.git diff --git a/src/linux/tunDevice.cpp b/src/linux/tunDevice.cpp index b34ae9d..ee6ac0e 100644 --- a/src/linux/tunDevice.cpp +++ b/src/linux/tunDevice.cpp @@ -11,14 +11,15 @@ * tunneling and relaying of packets of any protocol. * * - * Copyright (C) 2007-2008 Othmar Gsenger, Erwin Nindl, + * Copyright (C) 2007-2009 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. + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. * * Anytun is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -31,6 +32,7 @@ #include #include +#include #include #include @@ -46,8 +48,9 @@ #include "threadUtils.hpp" #include "log.h" #include "anytunError.h" +#include "sysExec.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) +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), sys_exec_(NULL) { struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); @@ -155,19 +158,14 @@ void TunDevice::init_post() void TunDevice::do_ifconfig() { - std::ostringstream command; - command << "/sbin/ifconfig " << actual_name_ << " " << conf_.addr_.toString() - << " netmask " << conf_.netmask_.toString() << " mtu " << conf_.mtu_; - - int result = system(command.str().c_str()); - if(result == -1) - cLog.msg(Log::PRIO_ERROR) << "Execution of ifconfig failed: " << AnytunErrno(errno); - else { - if(WIFEXITED(result)) - cLog.msg(Log::PRIO_NOTICE) << "ifconfig returned " << WEXITSTATUS(result); - else if(WIFSIGNALED(result)) - cLog.msg(Log::PRIO_NOTICE) << "ifconfig terminated after signal " << WTERMSIG(result); - else - cLog.msg(Log::PRIO_ERROR) << "Execution of ifconfig: unkown error"; - } + std::ostringstream mtu_ss; + mtu_ss << conf_.mtu_; + StringVector args = boost::assign::list_of(actual_name_)(conf_.addr_.toString())("netmask")(conf_.netmask_.toString())("mtu")(mtu_ss.str()); + sys_exec_ = new SysExec("/sbin/ifconfig", args); +} + +void TunDevice::waitUntilReady() +{ + if(sys_exec_) + SysExec::waitAndDestroy(sys_exec_); }