Skip to content

Add optional param for additional interface IP #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions GRETunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ int main(int argc, char* argv[])
{
SetUnhandledExceptionFilter(unhandled_handler);
std::cout << "GRE Tunnel for Windows" << std::endl << std::endl;
if (argc < 5 || argc > 7) {
if (argc < 5 || argc > 8) {
std::cerr << "At least 2 arguments must be given" << std::endl <<
"Arguments: gre_tunnel.exe GRE_BIND_IP GRE_SERVER INTERFACE_IP GATEWAY_IP [CIDR (30)] [ADAPTER_NAME]" << std::endl;
"Arguments: gre_tunnel.exe GRE_BIND_IP GRE_SERVER INTERFACE_IP GATEWAY_IP [CIDR (30)] [ADAPTER_NAME] [ADDITIONAL PUBLIC IP]" << std::endl;
return 0;
}
configure_logging();
Expand All @@ -105,6 +105,7 @@ int main(int argc, char* argv[])
const wchar_t* adapter_name;
const char* _adapter_name;
int cidr;
const char* additional_ip;

// Default CIDR is 30
if (argc >= 6) {
Expand All @@ -114,7 +115,7 @@ int main(int argc, char* argv[])
else
cidr = 30;

if (argc == 7)
if (argc >= 7)
{
adapter_name = GetWC(argv[6]);
_adapter_name = argv[6];
Expand All @@ -125,6 +126,13 @@ int main(int argc, char* argv[])
_adapter_name = "GRE_Tunnel";
}

if (argc >= 8)
{
additional_ip = argv[7];
}
else
additional_ip = "";

std::cout << "My IP on the GRE network: " << bind_ip << "/" << cidr << std::endl <<
"GRE server IP : " << server_ip << std::endl <<
"GRE server IP (Gateway) : " << gateway_ip << std::endl <<
Expand Down Expand Up @@ -184,6 +192,14 @@ int main(int argc, char* argv[])
LOG(INFO) << comm;
system(comm);

if (argc >= 8)
{
memset(comm, '0', 256);
sprintf_s(comm, 256, "netsh interface ipv4 add address \"%s\" %s 255.255.255.255", _adapter_name, additional_ip);
LOG(INFO) << comm;
system(comm);
}



gre = new GRE(server_ip, gre_bind_ip);
Expand Down