From 225aa2a55d9ffc069392ee6c8d303acf0ffe2aee Mon Sep 17 00:00:00 2001 From: DcruBro Date: Thu, 18 Dec 2025 07:55:35 +0100 Subject: [PATCH] Create wintun interface if not found --- CMakeLists.txt | 2 +- src/common/utils.cpp | 2 +- src/common/virtual_interface.cpp | 16 ++++++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c9c6b02..9ae0fe8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.16) # If MAJOR is 0, and MINOR > 0, Version is BETA project(ColumnLynx - VERSION 0.2.0 + VERSION 0.3.0 LANGUAGES CXX ) diff --git a/src/common/utils.cpp b/src/common/utils.cpp index c7ec622..ebf6612 100644 --- a/src/common/utils.cpp +++ b/src/common/utils.cpp @@ -49,7 +49,7 @@ namespace ColumnLynx::Utils { } std::string getVersion() { - return "b0.2"; + return "b0.3"; } unsigned short serverPort() { diff --git a/src/common/virtual_interface.cpp b/src/common/virtual_interface.cpp index d2caf0f..91f70a5 100644 --- a/src/common/virtual_interface.cpp +++ b/src/common/virtual_interface.cpp @@ -18,6 +18,7 @@ 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 WINTUN_CREATE_ADAPTER_FUNC* pWintunCreateAdapter; static void InitializeWintun() { @@ -47,6 +48,7 @@ static void InitializeWintun() RESOLVE(WintunReleaseReceivePacket, WINTUN_RELEASE_RECEIVE_PACKET_FUNC) RESOLVE(WintunAllocateSendPacket, WINTUN_ALLOCATE_SEND_PACKET_FUNC) RESOLVE(WintunSendPacket, WINTUN_SEND_PACKET_FUNC) + RESOLVE(WintunCreateAdapter, WINTUN_CREATE_ADAPTER_FUNC) #undef RESOLVE } @@ -113,12 +115,18 @@ namespace ColumnLynx::Net { InitializeWintun(); - mAdapter = pWintunOpenAdapter( - std::wstring(ifName.begin(), ifName.end()).c_str() - ); + mAdapter = pWintunOpenAdapter(ifaceName); + + if (!mAdapter) { + mAdapter = pWintunCreateAdapter( + ifaceName, + L"ColumnLynx", + nullptr + ); + } if (!mAdapter) - throw std::runtime_error("Wintun adapter not found"); + throw std::runtime_error("Failed to open or create Wintun adapter"); mSession = pWintunStartSession(mAdapter, 0x200000); if (!mSession)