* 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 <satp@wirdorange.org>
*
* 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
#include <string.h>
#include <sstream>
+#include <boost/assign.hpp>
#include <fcntl.h>
#include <sys/ioctl.h>
#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));
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_);
}