Commit 32412894 authored by nanamicat's avatar nanamicat

postup

parent 2b3da8cf
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
namespace po = boost::program_options;
in_addr_t remote; in_addr_t remote;
auto cipher = "Mathematics is the art of giving the same name to different things"; auto cipher = "Mathematics is the art of giving the same name to different things";
...@@ -62,30 +65,28 @@ void outbound(int raw, int tun) { ...@@ -62,30 +65,28 @@ void outbound(int raw, int tun) {
perror("outbound read"); perror("outbound read");
} }
namespace po = boost::program_options;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
po::options_description desc("Allowed options"); po::options_description desc("Allowed options");
desc.add_options() desc.add_options()
("help", "produce help message") ("help", "produce help message")
("IP,i", po::value<std::string>(), "IP to connect") ("IP,i", po::value<std::string>(), "IP to connect")
("dev,d", po::value<std::string>(), "tun device name"); ("dev,d", po::value<std::string>(), "tun device name")
("postup,p", po::value<std::string>(), "post up script");
po::variables_map vm; po::variables_map args;
po::store(po::parse_command_line(argc, argv, desc), vm); po::store(po::parse_command_line(argc, argv, desc), args);
po::notify(vm); po::notify(args);
if (vm.count("help") || !vm.count("IP") || !vm.count("dev")) { if (args.count("help") || !args.count("IP") || !args.count("dev")) {
std::cout << desc << std::endl; std::cout << desc << std::endl;
return -1; return -1;
} }
ifreq ifr{}; ifreq ifr{};
ifr.ifr_flags = IFF_TUN | IFF_NO_PI; ifr.ifr_flags = IFF_TUN | IFF_NO_PI | IFF_UP;
strcpy(ifr.ifr_name, vm["dev"].as<std::string>().c_str()); strcpy(ifr.ifr_name, args["dev"].as<std::string>().c_str());
remote = inet_addr(vm["IP"].as<std::string>().c_str()); remote = inet_addr(args["IP"].as<std::string>().c_str());
auto raw = socket(AF_INET, SOCK_RAW, IPPROTO_IPIP); auto raw = socket(AF_INET, SOCK_RAW, IPPROTO_IPIP);
if (raw < 0) { if (raw < 0) {
...@@ -103,6 +104,10 @@ int main(int argc, char *argv[]) { ...@@ -103,6 +104,10 @@ int main(int argc, char *argv[]) {
return -1; return -1;
} }
if (args.count("postup")) {
system(args["postup"].as<std::string>().c_str());
}
std::thread t1(inbound, raw, tun); std::thread t1(inbound, raw, tun);
std::thread t2(outbound, raw, tun); std::thread t2(outbound, raw, tun);
t1.join(); t1.join();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment