Create wintun interface if not found

This commit is contained in:
2025-12-18 07:55:35 +01:00
parent cab1362053
commit 225aa2a55d
3 changed files with 14 additions and 6 deletions

View File

@@ -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
)

View File

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

View File

@@ -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)