Compare commits
10 Commits
714aa52f98
...
b0.3
| Author | SHA1 | Date | |
|---|---|---|---|
| f99036c523 | |||
| 3eadd41a00 | |||
| 8923f45356 | |||
| 471224b043 | |||
| cb0f674c52 | |||
| 33bbd7cce6 | |||
| f9c5c56a1b | |||
| 17dd504a7a | |||
| 9f52bdd54c | |||
| 29e90938c5 |
@@ -327,7 +327,15 @@ namespace ColumnLynx::Net {
|
|||||||
);
|
);
|
||||||
system(cmd);
|
system(cmd);
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
char cmd[256];
|
char cmd[512];
|
||||||
|
// Remove any persistent routes associated with this interface
|
||||||
|
snprintf(cmd, sizeof(cmd),
|
||||||
|
"netsh routing ip delete persistentroute all name=\"%s\"",
|
||||||
|
mIfName.c_str()
|
||||||
|
);
|
||||||
|
system(cmd);
|
||||||
|
|
||||||
|
// Reset to DHCP
|
||||||
snprintf(cmd, sizeof(cmd),
|
snprintf(cmd, sizeof(cmd),
|
||||||
"netsh interface ip set address name=\"%s\" dhcp",
|
"netsh interface ip set address name=\"%s\" dhcp",
|
||||||
mIfName.c_str()
|
mIfName.c_str()
|
||||||
@@ -420,7 +428,11 @@ namespace ColumnLynx::Net {
|
|||||||
uint32_t maskInt = (prefixLen == 0) ? 0 : (0xFFFFFFFF << (32 - prefixLen));
|
uint32_t maskInt = (prefixLen == 0) ? 0 : (0xFFFFFFFF << (32 - prefixLen));
|
||||||
mask = ipv4ToString(maskInt);
|
mask = ipv4ToString(maskInt);
|
||||||
|
|
||||||
char cmd[256];
|
// Calculate network address from IP and mask
|
||||||
|
uint32_t networkInt = (clientIP & maskInt);
|
||||||
|
std::string network = ipv4ToString(networkInt);
|
||||||
|
|
||||||
|
char cmd[512];
|
||||||
|
|
||||||
// 1. Set the static IP + mask + gateway
|
// 1. Set the static IP + mask + gateway
|
||||||
snprintf(cmd, sizeof(cmd),
|
snprintf(cmd, sizeof(cmd),
|
||||||
@@ -436,6 +448,14 @@ namespace ColumnLynx::Net {
|
|||||||
);
|
);
|
||||||
system(cmd);
|
system(cmd);
|
||||||
|
|
||||||
|
// 3. Add route for the VPN network to go through the TUN interface
|
||||||
|
// This is critical: tells Windows to send packets destined for the server/network through the TUN interface
|
||||||
|
snprintf(cmd, sizeof(cmd),
|
||||||
|
"netsh routing ip add persistentroute dest=%s/%d name=\"%s\" nexthopcfg=%s",
|
||||||
|
network.c_str(), prefixLen, mIfName.c_str(), gw.c_str()
|
||||||
|
);
|
||||||
|
system(cmd);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user