Auto set route on macos
This commit is contained in:
@@ -46,7 +46,7 @@ namespace ColumnLynx::Net {
|
||||
|
||||
bool configureIP(uint32_t clientIP, uint32_t serverIP,
|
||||
uint8_t prefixLen, uint16_t mtu);
|
||||
|
||||
|
||||
void resetIP();
|
||||
|
||||
std::vector<uint8_t> readPacket();
|
||||
|
||||
@@ -326,6 +326,13 @@ namespace ColumnLynx::Net {
|
||||
mIfName.c_str()
|
||||
);
|
||||
system(cmd);
|
||||
|
||||
// Wipe old routes
|
||||
//snprintf(cmd, sizeof(cmd),
|
||||
// "route -n delete -net %s",
|
||||
// mIfName.c_str()
|
||||
//);
|
||||
//system(cmd);
|
||||
#elif defined(_WIN32)
|
||||
char cmd[512];
|
||||
// Remove any persistent routes associated with this interface
|
||||
@@ -406,6 +413,12 @@ namespace ColumnLynx::Net {
|
||||
mIfName.c_str(), ipStr.c_str(), peerStr.c_str(), mtu, prefixStr.c_str());
|
||||
system(cmd);
|
||||
|
||||
// Host bits are auto-normalized by the kernel on macOS, so we don't need to worry about them not being zeroed out.
|
||||
snprintf(cmd, sizeof(cmd),
|
||||
"route -n add -net %s/%d -interface %s",
|
||||
ipStr.c_str(), prefixLen, mIfName.c_str());
|
||||
system(cmd);
|
||||
|
||||
Utils::log("Executed command: " + std::string(cmd));
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user