Compare commits
8 Commits
766f878a8d
...
beta
| Author | SHA1 | Date | |
|---|---|---|---|
| 4ba59fb23f | |||
| a78b98ac56 | |||
| 09806c3c0f | |||
| ff81bfed31 | |||
| 2343fdd1e2 | |||
| 3ad98b8403 | |||
| 9e5e728438 | |||
| d20bee9e60 |
@@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.16)
|
||||
# If MAJOR is 0, and MINOR > 0, Version is BETA
|
||||
|
||||
project(ColumnLynx
|
||||
VERSION 0.0.3
|
||||
VERSION 0.0.4
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
|
||||
@@ -49,9 +49,9 @@ namespace ColumnLynx::Net {
|
||||
const std::string& getName() const;
|
||||
int getFd() const; // For ASIO integration (on POSIX)
|
||||
|
||||
static inline std::string ipToString(uint32_t ip) {
|
||||
static inline std::string ipv4ToString(uint32_t ip) {
|
||||
struct in_addr addr;
|
||||
addr.s_addr = ip; // expected in network byte order
|
||||
addr.s_addr = htonl(ip);
|
||||
|
||||
char buf[INET_ADDRSTRLEN];
|
||||
if (!inet_ntop(AF_INET, &addr, buf, sizeof(buf)))
|
||||
@@ -60,6 +60,12 @@ namespace ColumnLynx::Net {
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
static inline uint32_t prefixLengthToNetmask(uint8_t prefixLen) {
|
||||
if (prefixLen == 0) return 0;
|
||||
uint32_t mask = (0xFFFFFFFF << (32 - prefixLen)) & 0xFFFFFFFF;
|
||||
return htonl(mask); // convert to network byte order
|
||||
}
|
||||
|
||||
private:
|
||||
bool mApplyLinuxIP(uint32_t clientIP, uint32_t serverIP, uint8_t prefixLen, uint16_t mtu);
|
||||
bool mApplyMacOSIP(uint32_t clientIP, uint32_t serverIP, uint8_t prefixLen, uint16_t mtu);
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace ColumnLynx::Utils {
|
||||
}
|
||||
|
||||
std::string getVersion() {
|
||||
return "a0.3";
|
||||
return "a0.4";
|
||||
}
|
||||
|
||||
unsigned short serverPort() {
|
||||
|
||||
@@ -42,8 +42,11 @@ namespace ColumnLynx::Net {
|
||||
sc.sc_id = ctlInfo.ctl_id;
|
||||
sc.sc_unit = 0; // utun0 (0 = auto-assign)
|
||||
|
||||
if (connect(mFd, (struct sockaddr*)&sc, sizeof(sc)) < 0)
|
||||
if (connect(mFd, (struct sockaddr*)&sc, sizeof(sc)) < 0) {
|
||||
if (errno == EPERM)
|
||||
throw std::runtime_error("connect(AF_SYS_CONTROL) failed: Insufficient permissions (try running as root)");
|
||||
throw std::runtime_error("connect(AF_SYS_CONTROL) failed: " + std::string(strerror(errno)));
|
||||
}
|
||||
|
||||
// Retrieve actual utun device name
|
||||
struct sockaddr_storage addr;
|
||||
@@ -158,8 +161,8 @@ namespace ColumnLynx::Net {
|
||||
{
|
||||
char cmd[512];
|
||||
|
||||
std::string ipStr = ipToString(clientIP);
|
||||
std::string peerStr = ipToString(serverIP);
|
||||
std::string ipStr = ipv4ToString(clientIP);
|
||||
std::string peerStr = ipv4ToString(serverIP);
|
||||
|
||||
snprintf(cmd, sizeof(cmd),
|
||||
"ip addr add %s/%d peer %s dev %s",
|
||||
@@ -181,14 +184,17 @@ namespace ColumnLynx::Net {
|
||||
{
|
||||
char cmd[512];
|
||||
|
||||
std::string ipStr = ipToString(clientIP);
|
||||
std::string peerStr = ipToString(serverIP);
|
||||
std::string ipStr = ipv4ToString(clientIP);
|
||||
std::string peerStr = ipv4ToString(serverIP);
|
||||
|
||||
// Set netmask (/24 CIDR temporarily with raw command, improve later)
|
||||
snprintf(cmd, sizeof(cmd),
|
||||
"ifconfig utun0 %s %s mtu %d up",
|
||||
"ifconfig utun0 %s %s mtu %d netmask 255.255.255.0 up",
|
||||
ipStr.c_str(), peerStr.c_str(), mtu);
|
||||
system(cmd);
|
||||
|
||||
Utils::log("Executed command: " + std::string(cmd));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -200,8 +206,8 @@ namespace ColumnLynx::Net {
|
||||
{
|
||||
#ifdef _WIN32
|
||||
char ip[32], gw[32];
|
||||
strcpy(ip, ipToString(clientIP).c_str());
|
||||
strcpy(gw, ipToString(serverIP).c_str());
|
||||
strcpy(ip, ipv4ToString(clientIP).c_str());
|
||||
strcpy(gw, ipv4ToString(serverIP).c_str());
|
||||
|
||||
char cmd[256];
|
||||
snprintf(cmd, sizeof(cmd),
|
||||
|
||||
@@ -107,7 +107,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
auto session = SessionRegistry::getInstance().getByIP(dstIP);
|
||||
if (!session) {
|
||||
Utils::warn("TUN: No session found for destination IP " + VirtualInterface::ipToString(dstIP));
|
||||
Utils::warn("TUN: No session found for destination IP " + VirtualInterface::ipv4ToString(dstIP));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user