Compare commits

8 Commits

Author SHA1 Message Date
4ba59fb23f Merge pull request 'First working alpha, version a0.4.' (#6) from dev into beta
Reviewed-on: #6
2025-11-18 20:07:30 +00:00
a78b98ac56 rename iptostring 2025-11-18 20:12:45 +01:00
09806c3c0f test 2025-11-14 20:36:19 +01:00
ff81bfed31 Temporary /24 netmask for macOS 2025-11-14 20:29:25 +01:00
2343fdd1e2 htonl in ipToString 2025-11-14 19:25:52 +01:00
3ad98b8403 root permissions check and version counter update 2025-11-13 16:04:39 +01:00
9e5e728438 Merge pull request 'Add legal clarification' (#3) from dev into beta
Reviewed-on: #3
2025-11-10 15:58:18 +00:00
d20bee9e60 Merge pull request 'Update license' (#1) from dev into beta
Reviewed-on: #1
2025-11-10 15:15:10 +00:00
5 changed files with 25 additions and 13 deletions

View File

@@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.16)
# If MAJOR is 0, and MINOR > 0, Version is BETA # If MAJOR is 0, and MINOR > 0, Version is BETA
project(ColumnLynx project(ColumnLynx
VERSION 0.0.3 VERSION 0.0.4
LANGUAGES CXX LANGUAGES CXX
) )

View File

@@ -49,9 +49,9 @@ namespace ColumnLynx::Net {
const std::string& getName() const; const std::string& getName() const;
int getFd() const; // For ASIO integration (on POSIX) 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; struct in_addr addr;
addr.s_addr = ip; // expected in network byte order addr.s_addr = htonl(ip);
char buf[INET_ADDRSTRLEN]; char buf[INET_ADDRSTRLEN];
if (!inet_ntop(AF_INET, &addr, buf, sizeof(buf))) if (!inet_ntop(AF_INET, &addr, buf, sizeof(buf)))
@@ -60,6 +60,12 @@ namespace ColumnLynx::Net {
return std::string(buf); 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: private:
bool mApplyLinuxIP(uint32_t clientIP, uint32_t serverIP, uint8_t prefixLen, uint16_t mtu); 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); bool mApplyMacOSIP(uint32_t clientIP, uint32_t serverIP, uint8_t prefixLen, uint16_t mtu);

View File

@@ -37,7 +37,7 @@ namespace ColumnLynx::Utils {
} }
std::string getVersion() { std::string getVersion() {
return "a0.3"; return "a0.4";
} }
unsigned short serverPort() { unsigned short serverPort() {

View File

@@ -42,8 +42,11 @@ namespace ColumnLynx::Net {
sc.sc_id = ctlInfo.ctl_id; sc.sc_id = ctlInfo.ctl_id;
sc.sc_unit = 0; // utun0 (0 = auto-assign) 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))); throw std::runtime_error("connect(AF_SYS_CONTROL) failed: " + std::string(strerror(errno)));
}
// Retrieve actual utun device name // Retrieve actual utun device name
struct sockaddr_storage addr; struct sockaddr_storage addr;
@@ -158,8 +161,8 @@ namespace ColumnLynx::Net {
{ {
char cmd[512]; char cmd[512];
std::string ipStr = ipToString(clientIP); std::string ipStr = ipv4ToString(clientIP);
std::string peerStr = ipToString(serverIP); std::string peerStr = ipv4ToString(serverIP);
snprintf(cmd, sizeof(cmd), snprintf(cmd, sizeof(cmd),
"ip addr add %s/%d peer %s dev %s", "ip addr add %s/%d peer %s dev %s",
@@ -181,14 +184,17 @@ namespace ColumnLynx::Net {
{ {
char cmd[512]; char cmd[512];
std::string ipStr = ipToString(clientIP); std::string ipStr = ipv4ToString(clientIP);
std::string peerStr = ipToString(serverIP); std::string peerStr = ipv4ToString(serverIP);
// Set netmask (/24 CIDR temporarily with raw command, improve later)
snprintf(cmd, sizeof(cmd), 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); ipStr.c_str(), peerStr.c_str(), mtu);
system(cmd); system(cmd);
Utils::log("Executed command: " + std::string(cmd));
return true; return true;
} }
@@ -200,8 +206,8 @@ namespace ColumnLynx::Net {
{ {
#ifdef _WIN32 #ifdef _WIN32
char ip[32], gw[32]; char ip[32], gw[32];
strcpy(ip, ipToString(clientIP).c_str()); strcpy(ip, ipv4ToString(clientIP).c_str());
strcpy(gw, ipToString(serverIP).c_str()); strcpy(gw, ipv4ToString(serverIP).c_str());
char cmd[256]; char cmd[256];
snprintf(cmd, sizeof(cmd), snprintf(cmd, sizeof(cmd),

View File

@@ -107,7 +107,7 @@ int main(int argc, char** argv) {
auto session = SessionRegistry::getInstance().getByIP(dstIP); auto session = SessionRegistry::getInstance().getByIP(dstIP);
if (!session) { 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; continue;
} }