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:
@@ -100,6 +100,16 @@ endforeach()
|
||||
file(GLOB_RECURSE COMMON_SRC CONFIGURE_DEPENDS src/common/*.cpp)
|
||||
add_library(common STATIC ${COMMON_SRC})
|
||||
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
|
||||
${PROJECT_SOURCE_DIR}/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)
|
||||
add_executable(client ${CLIENT_SRC})
|
||||
target_link_libraries(client PRIVATE common sodium cxxopts::cxxopts)
|
||||
if (WIN32)
|
||||
target_link_libraries(client PRIVATE
|
||||
dbghelp
|
||||
)
|
||||
endif()
|
||||
target_include_directories(client PRIVATE
|
||||
${PROJECT_SOURCE_DIR}/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)
|
||||
add_executable(server ${SERVER_SRC})
|
||||
target_link_libraries(server PRIVATE common sodium cxxopts::cxxopts)
|
||||
if (WIN32)
|
||||
target_link_libraries(server PRIVATE
|
||||
dbghelp
|
||||
)
|
||||
endif()
|
||||
target_include_directories(server PRIVATE
|
||||
${PROJECT_SOURCE_DIR}/include
|
||||
${sodium_SOURCE_DIR}/src/libsodium/include
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <sys/poll.h>
|
||||
#elif defined(_WIN32)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define WINTUN_STATIC
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
@@ -27,11 +27,13 @@ void signalHandler(int signum) {
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
// Capture SIGINT and SIGTERM for graceful shutdown
|
||||
#if !defined(_WIN32)
|
||||
struct sigaction action;
|
||||
memset(&action, 0, sizeof(struct sigaction));
|
||||
action.sa_handler = signalHandler;
|
||||
sigaction(SIGINT, &action, nullptr);
|
||||
sigaction(SIGTERM, &action, nullptr);
|
||||
#endif
|
||||
|
||||
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.");
|
||||
|
||||
#if defined(__WIN32__)
|
||||
WintunInitialize();
|
||||
//WintunInitialize();
|
||||
#endif
|
||||
|
||||
std::shared_ptr<VirtualInterface> tun = std::make_shared<VirtualInterface>(optionsObj["interface"].as<std::string>());
|
||||
|
||||
@@ -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.
|
||||
|
||||
#include <columnlynx/client/net/tcp/tcp_client.hpp>
|
||||
#include <arpa/inet.h>
|
||||
//#include <arpa/inet.h>
|
||||
|
||||
namespace ColumnLynx::Net::TCP {
|
||||
void TCPClient::start() {
|
||||
@@ -26,9 +26,13 @@ namespace ColumnLynx::Net::TCP {
|
||||
Utils::log("Sending handshake init to server.");
|
||||
|
||||
// Check if hostname or IPv4/IPv6
|
||||
sockaddr_in addr4{};
|
||||
sockaddr_in6 addr6{};
|
||||
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
|
||||
try {
|
||||
asio::ip::make_address(mHost);
|
||||
self->mIsHostDomain = false; // IPv4 or IPv6 literal
|
||||
} catch (const asio::system_error&) {
|
||||
self->mIsHostDomain = true; // hostname / domain
|
||||
}
|
||||
|
||||
|
||||
std::vector<uint8_t> payload;
|
||||
payload.reserve(1 + crypto_box_PUBLICKEYBYTES);
|
||||
|
||||
@@ -10,37 +10,43 @@
|
||||
|
||||
static HMODULE gWintun = nullptr;
|
||||
|
||||
static WintunOpenAdapterFn WintunOpenAdapter;
|
||||
static WintunStartSessionFn WintunStartSession;
|
||||
static WintunEndSessionFn WintunEndSession;
|
||||
static WintunGetReadWaitEventFn WintunGetReadWaitEvent;
|
||||
static WintunReceivePacketFn WintunReceivePacket;
|
||||
static WintunReleaseReceivePacketFn WintunReleaseReceivePacket;
|
||||
static WintunAllocateSendPacketFn WintunAllocateSendPacket;
|
||||
static WintunSendPacketFn WintunSendPacket;
|
||||
static WINTUN_OPEN_ADAPTER_FUNC* pWintunOpenAdapter;
|
||||
static WINTUN_START_SESSION_FUNC* pWintunStartSession;
|
||||
static WINTUN_END_SESSION_FUNC* pWintunEndSession;
|
||||
static WINTUN_GET_READ_WAIT_EVENT_FUNC* pWintunGetReadWaitEvent;
|
||||
static WINTUN_RECEIVE_PACKET_FUNC* pWintunReceivePacket;
|
||||
static WINTUN_RELEASE_RECEIVE_PACKET_FUNC* pWintunReleaseReceivePacket;
|
||||
static WINTUN_ALLOCATE_SEND_PACKET_FUNC* pWintunAllocateSendPacket;
|
||||
static WINTUN_SEND_PACKET_FUNC* pWintunSendPacket;
|
||||
|
||||
static void InitializeWintun()
|
||||
{
|
||||
if (gWintun)
|
||||
return;
|
||||
|
||||
gWintun = LoadLibraryExW(L"wintun.dll", nullptr,
|
||||
LOAD_LIBRARY_SEARCH_APPLICATION_DIR);
|
||||
gWintun = LoadLibraryExW(
|
||||
L"wintun.dll",
|
||||
nullptr,
|
||||
LOAD_LIBRARY_SEARCH_APPLICATION_DIR
|
||||
);
|
||||
|
||||
if (!gWintun)
|
||||
throw std::runtime_error("Failed to load wintun.dll");
|
||||
|
||||
#define RESOLVE(name) \
|
||||
name = (name##Fn)GetProcAddress(gWintun, #name); \
|
||||
if (!name) throw std::runtime_error("Missing Wintun symbol: " #name);
|
||||
#define RESOLVE(name, type) \
|
||||
p##name = reinterpret_cast<type*>( \
|
||||
GetProcAddress(gWintun, #name)); \
|
||||
if (!p##name) \
|
||||
throw std::runtime_error("Missing Wintun symbol: " #name);
|
||||
|
||||
RESOLVE(WintunOpenAdapter)
|
||||
RESOLVE(WintunStartSession)
|
||||
RESOLVE(WintunEndSession)
|
||||
RESOLVE(WintunGetReadWaitEvent)
|
||||
RESOLVE(WintunReceivePacket)
|
||||
RESOLVE(WintunReleaseReceivePacket)
|
||||
RESOLVE(WintunAllocateSendPacket)
|
||||
RESOLVE(WintunSendPacket)
|
||||
RESOLVE(WintunOpenAdapter, WINTUN_OPEN_ADAPTER_FUNC)
|
||||
RESOLVE(WintunStartSession, WINTUN_START_SESSION_FUNC)
|
||||
RESOLVE(WintunEndSession, WINTUN_END_SESSION_FUNC)
|
||||
RESOLVE(WintunGetReadWaitEvent, WINTUN_GET_READ_WAIT_EVENT_FUNC)
|
||||
RESOLVE(WintunReceivePacket, WINTUN_RECEIVE_PACKET_FUNC)
|
||||
RESOLVE(WintunReleaseReceivePacket, WINTUN_RELEASE_RECEIVE_PACKET_FUNC)
|
||||
RESOLVE(WintunAllocateSendPacket, WINTUN_ALLOCATE_SEND_PACKET_FUNC)
|
||||
RESOLVE(WintunSendPacket, WINTUN_SEND_PACKET_FUNC)
|
||||
|
||||
#undef RESOLVE
|
||||
}
|
||||
@@ -107,19 +113,18 @@ namespace ColumnLynx::Net {
|
||||
|
||||
InitializeWintun();
|
||||
|
||||
mAdapter = WintunOpenAdapter(
|
||||
L"ColumnLynx",
|
||||
mAdapter = pWintunOpenAdapter(
|
||||
std::wstring(ifName.begin(), ifName.end()).c_str()
|
||||
);
|
||||
|
||||
if (!mAdapter)
|
||||
throw std::runtime_error("Wintun adapter not found");
|
||||
|
||||
mSession = WintunStartSession(mAdapter, 0x200000);
|
||||
mSession = pWintunStartSession(mAdapter, 0x200000);
|
||||
if (!mSession)
|
||||
throw std::runtime_error("Failed to start Wintun session");
|
||||
|
||||
mHandle = WintunGetReadWaitEvent(mSession);
|
||||
mHandle = pWintunGetReadWaitEvent(mSession);
|
||||
mFd = -1;
|
||||
|
||||
#else
|
||||
@@ -134,7 +139,7 @@ namespace ColumnLynx::Net {
|
||||
close(mFd);
|
||||
#elif defined(_WIN32)
|
||||
if (mSession)
|
||||
WintunEndSession(mSession);
|
||||
pWintunEndSession(mSession);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -200,14 +205,13 @@ namespace ColumnLynx::Net {
|
||||
|
||||
#elif defined(_WIN32)
|
||||
|
||||
WINTUN_PACKET* packet = WintunReceivePacket(mSession, nullptr);
|
||||
DWORD size = 0;
|
||||
BYTE* packet = pWintunReceivePacket(mSession, &size);
|
||||
if (!packet)
|
||||
return {};
|
||||
|
||||
std::vector<uint8_t> buf(packet->Data,
|
||||
packet->Data + packet->Length);
|
||||
|
||||
WintunReleaseReceivePacket(mSession, packet);
|
||||
std::vector<uint8_t> buf(packet, packet + size);
|
||||
pWintunReleaseReceivePacket(mSession, packet);
|
||||
return buf;
|
||||
|
||||
#else
|
||||
@@ -252,15 +256,16 @@ namespace ColumnLynx::Net {
|
||||
|
||||
#elif defined(_WIN32)
|
||||
|
||||
WINTUN_PACKET* tx =
|
||||
WintunAllocateSendPacket(mSession,
|
||||
static_cast<DWORD>(packet.size()));
|
||||
BYTE* tx = pWintunAllocateSendPacket(
|
||||
mSession,
|
||||
static_cast<DWORD>(packet.size())
|
||||
);
|
||||
|
||||
if (!tx)
|
||||
throw std::runtime_error("WintunAllocateSendPacket failed");
|
||||
|
||||
memcpy(tx->Data, packet.data(), packet.size());
|
||||
WintunSendPacket(mSession, tx);
|
||||
|
||||
memcpy(tx, packet.data(), packet.size());
|
||||
pWintunSendPacket(mSession, tx);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -32,11 +32,13 @@ void signalHandler(int signum) {
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
// Capture SIGINT and SIGTERM for graceful shutdown
|
||||
#if !defined(_WIN32)
|
||||
struct sigaction action;
|
||||
memset(&action, 0, sizeof(struct sigaction));
|
||||
action.sa_handler = signalHandler;
|
||||
sigaction(SIGINT, &action, nullptr);
|
||||
sigaction(SIGTERM, &action, nullptr);
|
||||
#endif
|
||||
|
||||
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.");
|
||||
|
||||
#if defined(__WIN32__)
|
||||
WintunInitialize();
|
||||
//WintunInitialize();
|
||||
#endif
|
||||
|
||||
std::unordered_map<std::string, std::string> config = Utils::getConfigMap(optionsObj["config"].as<std::string>());
|
||||
|
||||
Reference in New Issue
Block a user