Kinda working Windows version

Needs these DLLs:
- libgcc_s_seh-1.dll
- libstdc++-6.dll
- libwinpthread-1.dll
- wintun.dll
This commit is contained in:
2025-12-17 19:11:28 +01:00
parent c047cb90f0
commit cab1362053
6 changed files with 77 additions and 43 deletions

View File

@@ -100,6 +100,16 @@ endforeach()
file(GLOB_RECURSE COMMON_SRC CONFIGURE_DEPENDS src/common/*.cpp) file(GLOB_RECURSE COMMON_SRC CONFIGURE_DEPENDS src/common/*.cpp)
add_library(common STATIC ${COMMON_SRC}) add_library(common STATIC ${COMMON_SRC})
target_link_libraries(common PUBLIC sodium cxxopts::cxxopts) target_link_libraries(common PUBLIC sodium cxxopts::cxxopts)
if (WIN32)
target_link_libraries(common PUBLIC
ws2_32
iphlpapi
advapi32
mswsock
)
endif()
target_include_directories(common PUBLIC target_include_directories(common PUBLIC
${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/include
${sodium_SOURCE_DIR}/src/libsodium/include ${sodium_SOURCE_DIR}/src/libsodium/include
@@ -114,6 +124,11 @@ target_compile_definitions(common PUBLIC ASIO_STANDALONE)
file(GLOB_RECURSE CLIENT_SRC CONFIGURE_DEPENDS src/client/*.cpp) file(GLOB_RECURSE CLIENT_SRC CONFIGURE_DEPENDS src/client/*.cpp)
add_executable(client ${CLIENT_SRC}) add_executable(client ${CLIENT_SRC})
target_link_libraries(client PRIVATE common sodium cxxopts::cxxopts) target_link_libraries(client PRIVATE common sodium cxxopts::cxxopts)
if (WIN32)
target_link_libraries(client PRIVATE
dbghelp
)
endif()
target_include_directories(client PRIVATE target_include_directories(client PRIVATE
${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/include
${sodium_SOURCE_DIR}/src/libsodium/include ${sodium_SOURCE_DIR}/src/libsodium/include
@@ -129,6 +144,11 @@ set_target_properties(client PROPERTIES OUTPUT_NAME "columnlynx_client")
file(GLOB_RECURSE SERVER_SRC CONFIGURE_DEPENDS src/server/*.cpp) file(GLOB_RECURSE SERVER_SRC CONFIGURE_DEPENDS src/server/*.cpp)
add_executable(server ${SERVER_SRC}) add_executable(server ${SERVER_SRC})
target_link_libraries(server PRIVATE common sodium cxxopts::cxxopts) target_link_libraries(server PRIVATE common sodium cxxopts::cxxopts)
if (WIN32)
target_link_libraries(server PRIVATE
dbghelp
)
endif()
target_include_directories(server PRIVATE target_include_directories(server PRIVATE
${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/include
${sodium_SOURCE_DIR}/src/libsodium/include ${sodium_SOURCE_DIR}/src/libsodium/include

View File

@@ -29,6 +29,7 @@
#include <sys/poll.h> #include <sys/poll.h>
#elif defined(_WIN32) #elif defined(_WIN32)
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define WINTUN_STATIC
#include <windows.h> #include <windows.h>
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>

View File

@@ -27,11 +27,13 @@ void signalHandler(int signum) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
// Capture SIGINT and SIGTERM for graceful shutdown // Capture SIGINT and SIGTERM for graceful shutdown
#if !defined(_WIN32)
struct sigaction action; struct sigaction action;
memset(&action, 0, sizeof(struct sigaction)); memset(&action, 0, sizeof(struct sigaction));
action.sa_handler = signalHandler; action.sa_handler = signalHandler;
sigaction(SIGINT, &action, nullptr); sigaction(SIGINT, &action, nullptr);
sigaction(SIGTERM, &action, nullptr); sigaction(SIGTERM, &action, nullptr);
#endif
PanicHandler::init(); PanicHandler::init();
@@ -67,7 +69,7 @@ int main(int argc, char** argv) {
log("This software is licensed under the GPLv2 only OR the GPLv3. See LICENSES/ for details."); log("This software is licensed under the GPLv2 only OR the GPLv3. See LICENSES/ for details.");
#if defined(__WIN32__) #if defined(__WIN32__)
WintunInitialize(); //WintunInitialize();
#endif #endif
std::shared_ptr<VirtualInterface> tun = std::make_shared<VirtualInterface>(optionsObj["interface"].as<std::string>()); std::shared_ptr<VirtualInterface> tun = std::make_shared<VirtualInterface>(optionsObj["interface"].as<std::string>());

View File

@@ -3,7 +3,7 @@
// Distributed under the terms of the GNU General Public License, either version 2 only or version 3. See LICENSES/ for details. // Distributed under the terms of the GNU General Public License, either version 2 only or version 3. See LICENSES/ for details.
#include <columnlynx/client/net/tcp/tcp_client.hpp> #include <columnlynx/client/net/tcp/tcp_client.hpp>
#include <arpa/inet.h> //#include <arpa/inet.h>
namespace ColumnLynx::Net::TCP { namespace ColumnLynx::Net::TCP {
void TCPClient::start() { void TCPClient::start() {
@@ -26,9 +26,13 @@ namespace ColumnLynx::Net::TCP {
Utils::log("Sending handshake init to server."); Utils::log("Sending handshake init to server.");
// Check if hostname or IPv4/IPv6 // Check if hostname or IPv4/IPv6
sockaddr_in addr4{}; try {
sockaddr_in6 addr6{}; asio::ip::make_address(mHost);
self->mIsHostDomain = inet_pton(AF_INET, mHost.c_str(), (void*)(&addr4)) != 1 && inet_pton(AF_INET6, mHost.c_str(), (void*)(&addr6)) != 1; // Voodoo black magic self->mIsHostDomain = false; // IPv4 or IPv6 literal
} catch (const asio::system_error&) {
self->mIsHostDomain = true; // hostname / domain
}
std::vector<uint8_t> payload; std::vector<uint8_t> payload;
payload.reserve(1 + crypto_box_PUBLICKEYBYTES); payload.reserve(1 + crypto_box_PUBLICKEYBYTES);

View File

@@ -10,37 +10,43 @@
static HMODULE gWintun = nullptr; static HMODULE gWintun = nullptr;
static WintunOpenAdapterFn WintunOpenAdapter; static WINTUN_OPEN_ADAPTER_FUNC* pWintunOpenAdapter;
static WintunStartSessionFn WintunStartSession; static WINTUN_START_SESSION_FUNC* pWintunStartSession;
static WintunEndSessionFn WintunEndSession; static WINTUN_END_SESSION_FUNC* pWintunEndSession;
static WintunGetReadWaitEventFn WintunGetReadWaitEvent; static WINTUN_GET_READ_WAIT_EVENT_FUNC* pWintunGetReadWaitEvent;
static WintunReceivePacketFn WintunReceivePacket; static WINTUN_RECEIVE_PACKET_FUNC* pWintunReceivePacket;
static WintunReleaseReceivePacketFn WintunReleaseReceivePacket; static WINTUN_RELEASE_RECEIVE_PACKET_FUNC* pWintunReleaseReceivePacket;
static WintunAllocateSendPacketFn WintunAllocateSendPacket; static WINTUN_ALLOCATE_SEND_PACKET_FUNC* pWintunAllocateSendPacket;
static WintunSendPacketFn WintunSendPacket; static WINTUN_SEND_PACKET_FUNC* pWintunSendPacket;
static void InitializeWintun() static void InitializeWintun()
{ {
if (gWintun) if (gWintun)
return; return;
gWintun = LoadLibraryExW(L"wintun.dll", nullptr, gWintun = LoadLibraryExW(
LOAD_LIBRARY_SEARCH_APPLICATION_DIR); L"wintun.dll",
nullptr,
LOAD_LIBRARY_SEARCH_APPLICATION_DIR
);
if (!gWintun) if (!gWintun)
throw std::runtime_error("Failed to load wintun.dll"); throw std::runtime_error("Failed to load wintun.dll");
#define RESOLVE(name) \ #define RESOLVE(name, type) \
name = (name##Fn)GetProcAddress(gWintun, #name); \ p##name = reinterpret_cast<type*>( \
if (!name) throw std::runtime_error("Missing Wintun symbol: " #name); GetProcAddress(gWintun, #name)); \
if (!p##name) \
throw std::runtime_error("Missing Wintun symbol: " #name);
RESOLVE(WintunOpenAdapter) RESOLVE(WintunOpenAdapter, WINTUN_OPEN_ADAPTER_FUNC)
RESOLVE(WintunStartSession) RESOLVE(WintunStartSession, WINTUN_START_SESSION_FUNC)
RESOLVE(WintunEndSession) RESOLVE(WintunEndSession, WINTUN_END_SESSION_FUNC)
RESOLVE(WintunGetReadWaitEvent) RESOLVE(WintunGetReadWaitEvent, WINTUN_GET_READ_WAIT_EVENT_FUNC)
RESOLVE(WintunReceivePacket) RESOLVE(WintunReceivePacket, WINTUN_RECEIVE_PACKET_FUNC)
RESOLVE(WintunReleaseReceivePacket) RESOLVE(WintunReleaseReceivePacket, WINTUN_RELEASE_RECEIVE_PACKET_FUNC)
RESOLVE(WintunAllocateSendPacket) RESOLVE(WintunAllocateSendPacket, WINTUN_ALLOCATE_SEND_PACKET_FUNC)
RESOLVE(WintunSendPacket) RESOLVE(WintunSendPacket, WINTUN_SEND_PACKET_FUNC)
#undef RESOLVE #undef RESOLVE
} }
@@ -107,19 +113,18 @@ namespace ColumnLynx::Net {
InitializeWintun(); InitializeWintun();
mAdapter = WintunOpenAdapter( mAdapter = pWintunOpenAdapter(
L"ColumnLynx",
std::wstring(ifName.begin(), ifName.end()).c_str() std::wstring(ifName.begin(), ifName.end()).c_str()
); );
if (!mAdapter) if (!mAdapter)
throw std::runtime_error("Wintun adapter not found"); throw std::runtime_error("Wintun adapter not found");
mSession = WintunStartSession(mAdapter, 0x200000); mSession = pWintunStartSession(mAdapter, 0x200000);
if (!mSession) if (!mSession)
throw std::runtime_error("Failed to start Wintun session"); throw std::runtime_error("Failed to start Wintun session");
mHandle = WintunGetReadWaitEvent(mSession); mHandle = pWintunGetReadWaitEvent(mSession);
mFd = -1; mFd = -1;
#else #else
@@ -134,7 +139,7 @@ namespace ColumnLynx::Net {
close(mFd); close(mFd);
#elif defined(_WIN32) #elif defined(_WIN32)
if (mSession) if (mSession)
WintunEndSession(mSession); pWintunEndSession(mSession);
#endif #endif
} }
@@ -200,14 +205,13 @@ namespace ColumnLynx::Net {
#elif defined(_WIN32) #elif defined(_WIN32)
WINTUN_PACKET* packet = WintunReceivePacket(mSession, nullptr); DWORD size = 0;
BYTE* packet = pWintunReceivePacket(mSession, &size);
if (!packet) if (!packet)
return {}; return {};
std::vector<uint8_t> buf(packet->Data, std::vector<uint8_t> buf(packet, packet + size);
packet->Data + packet->Length); pWintunReleaseReceivePacket(mSession, packet);
WintunReleaseReceivePacket(mSession, packet);
return buf; return buf;
#else #else
@@ -252,15 +256,16 @@ namespace ColumnLynx::Net {
#elif defined(_WIN32) #elif defined(_WIN32)
WINTUN_PACKET* tx = BYTE* tx = pWintunAllocateSendPacket(
WintunAllocateSendPacket(mSession, mSession,
static_cast<DWORD>(packet.size())); static_cast<DWORD>(packet.size())
);
if (!tx) if (!tx)
throw std::runtime_error("WintunAllocateSendPacket failed"); throw std::runtime_error("WintunAllocateSendPacket failed");
memcpy(tx->Data, packet.data(), packet.size()); memcpy(tx, packet.data(), packet.size());
WintunSendPacket(mSession, tx); pWintunSendPacket(mSession, tx);
#endif #endif
} }

View File

@@ -32,11 +32,13 @@ void signalHandler(int signum) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
// Capture SIGINT and SIGTERM for graceful shutdown // Capture SIGINT and SIGTERM for graceful shutdown
#if !defined(_WIN32)
struct sigaction action; struct sigaction action;
memset(&action, 0, sizeof(struct sigaction)); memset(&action, 0, sizeof(struct sigaction));
action.sa_handler = signalHandler; action.sa_handler = signalHandler;
sigaction(SIGINT, &action, nullptr); sigaction(SIGINT, &action, nullptr);
sigaction(SIGTERM, &action, nullptr); sigaction(SIGTERM, &action, nullptr);
#endif
cxxopts::Options options("columnlynx_server", "ColumnLynx Server Application"); cxxopts::Options options("columnlynx_server", "ColumnLynx Server Application");
@@ -68,7 +70,7 @@ int main(int argc, char** argv) {
log("This software is licensed under the GPLv2 only OR the GPLv3. See LICENSES/ for details."); log("This software is licensed under the GPLv2 only OR the GPLv3. See LICENSES/ for details.");
#if defined(__WIN32__) #if defined(__WIN32__)
WintunInitialize(); //WintunInitialize();
#endif #endif
std::unordered_map<std::string, std::string> config = Utils::getConfigMap(optionsObj["config"].as<std::string>()); std::unordered_map<std::string, std::string> config = Utils::getConfigMap(optionsObj["config"].as<std::string>());