verbose logging of executed commands

This commit is contained in:
Jeff Becker 2020-08-10 16:48:13 -04:00
parent d9d63ba14b
commit b2e5a178a4
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
1 changed files with 15 additions and 12 deletions

View File

@ -274,6 +274,13 @@ main(int argc, char* argv[])
return 0;
}
void
Execute(std::string cmd)
{
std::cout << cmd << std::endl;
system(cmd.c_str());
}
void
AddRoute(std::string ip, std::string gateway)
{
@ -281,14 +288,13 @@ AddRoute(std::string ip, std::string gateway)
#ifdef __linux__
ss << "ip route add " << ip << "/32 via " << gateway;
#elif _WIN32
ss << "route ADD " << ip << " MASK 255.255.255.255 METRIC 2 " << gateway;
ss << "route ADD " << ip << " MASK 255.255.255.255 " << gateway << " METRIC 2";
#elif __APPLE__
ss << "route -n add -host " << ip << " " << gateway;
#else
#error unsupported platform
#endif
const auto cmd_str = ss.str();
system(cmd_str.c_str());
Execute(ss.str());
}
void
@ -298,14 +304,13 @@ DelRoute(std::string ip, std::string gateway)
#ifdef __linux__
ss << "ip route del " << ip << "/32 via " << gateway;
#elif _WIN32
ss << "route DELETE " << ip << " MASK 255.255.255.255 METRIC 2" << gateway;
ss << "route DELETE " << ip << " MASK 255.255.255.255 " << gateway << " METRIC 2";
#elif __APPLE__
ss << "route -n delete -host " << ip << " " << gateway;
#else
#error unsupported platform
#endif
const auto cmd_str = ss.str();
system(cmd_str.c_str());
Execute(ss.str());
}
void
@ -317,12 +322,11 @@ AddDefaultRouteViaInterface(std::string ifname)
#elif _WIN32
ss << "route ADD 0.0.0.0 MASK 0.0.0.0 " << ifname;
#elif __APPLE__
ss << "route -n add -net 0.0.0.0 " << ifname << " 0.0.0.0";
ss << "route -n add -net 0.0.0.0 -interface " << ifname;
#else
#error unsupported platform
#endif
const auto cmd_str = ss.str();
system(cmd_str.c_str());
Execute(ss.str());
}
void
@ -334,12 +338,11 @@ DelDefaultRouteViaInterface(std::string ifname)
#elif _WIN32
ss << "route DELETE 0.0.0.0 MASK 0.0.0.0 " << ifname;
#elif __APPLE__
ss << "route -n delete -net 0.0.0.0 " << ifname << " 0.0.0.0";
ss << "route -n delete -net 0.0.0.0 -interface " << ifname;
#else
#error unsupported platform
#endif
const auto cmd_str = ss.str();
system(cmd_str.c_str());
Execute(ss.str());
}
std::vector<std::string>