summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2009-10-04 18:42:37 +0000
committerChristian Pointner <equinox@anytun.org>2009-10-04 18:42:37 +0000
commitd9dad6eee3cdca8aade318d4e91ee1aa3d79d3f6 (patch)
tree3ba7301530710d97d1d980ae6782273a7e002cc1 /src
parentcleaned new exec script function (diff)
got rid of remaining system()
Diffstat (limited to 'src')
-rw-r--r--src/bsd/tunDevice.cpp32
-rw-r--r--src/linux/tunDevice.cpp21
2 files changed, 17 insertions, 36 deletions
diff --git a/src/bsd/tunDevice.cpp b/src/bsd/tunDevice.cpp
index 408434e..5521f9c 100644
--- a/src/bsd/tunDevice.cpp
+++ b/src/bsd/tunDevice.cpp
@@ -29,6 +29,9 @@
* along with anytun. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <sstream>
+#include <boost/assign.hpp>
+
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
@@ -42,8 +45,6 @@
#include <netinet/in.h>
#include <netinet/ip.h>
-#include <sstream>
-
#include "tunDevice.h"
#include "threadUtils.hpp"
#include "log.h"
@@ -250,34 +251,23 @@ int TunDevice::write(u_int8_t* buf, u_int32_t len)
void TunDevice::do_ifconfig()
{
- std::ostringstream command;
- command << "/sbin/ifconfig " << actual_name_ << " " << conf_.addr_.toString()
- << " netmask " << conf_.netmask_.toString() << " mtu " << conf_.mtu_;
+ 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());
if(conf_.type_ == TYPE_TUN)
- command << " up";
+ args.push_back("up");
else {
#if defined(__GNUC__) && defined(__OpenBSD__)
- command << " link0";
+ args.push_back("link0");
#elif defined(__GNUC__) && defined(__FreeBSD__)
- command << " up";
+ args.push_back("up");
#elif defined(__GNUC__) && defined(__NetBSD__)
- command << "";
+ // nothing to be done here
#else
#error This Device works just for OpenBSD, FreeBSD or NetBSD
#endif
}
- 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";
- }
-
+ anytun_exec("/sbin/ifconfig", args);
}
diff --git a/src/linux/tunDevice.cpp b/src/linux/tunDevice.cpp
index b34ae9d..d9019e0 100644
--- a/src/linux/tunDevice.cpp
+++ b/src/linux/tunDevice.cpp
@@ -31,6 +31,7 @@
#include <string.h>
#include <sstream>
+#include <boost/assign.hpp>
#include <fcntl.h>
#include <sys/ioctl.h>
@@ -46,6 +47,7 @@
#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)
{
@@ -155,19 +157,8 @@ 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());
+ anytun_exec("/sbin/ifconfig", args);
}