diff --git a/include/columnlynx/common/net/virtual_interface.hpp b/include/columnlynx/common/net/virtual_interface.hpp index f393fcf..f207b1f 100644 --- a/include/columnlynx/common/net/virtual_interface.hpp +++ b/include/columnlynx/common/net/virtual_interface.hpp @@ -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 readPacket(); diff --git a/src/common/virtual_interface.cpp b/src/common/virtual_interface.cpp index 9db549c..06b3461 100644 --- a/src/common/virtual_interface.cpp +++ b/src/common/virtual_interface.cpp @@ -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;