api: port nci package from wireguard-go

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2020-07-07 15:32:06 +02:00 committed by Jason A. Donenfeld
parent 6f55786c65
commit 3fa45fec71
5 changed files with 54 additions and 0 deletions

View File

@ -17,9 +17,11 @@ DllMain(_In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved)
case DLL_PROCESS_ATTACH:
ResourceModule = hinstDLL;
NamespaceInit();
NciInit();
break;
case DLL_PROCESS_DETACH:
NciCleanup();
NamespaceCleanup();
break;
}

View File

@ -21,3 +21,18 @@ NamespaceInit();
void
NamespaceCleanup();
_Return_type_success_(return ==
0) extern DWORD(WINAPI *NciSetConnectionName)(_In_ LPCGUID Guid, _In_z_ LPCWSTR NewName);
_Return_type_success_(return == 0) extern DWORD(WINAPI *NciGetConnectionName)(
_In_ LPCGUID Guid,
_Out_z_bytecap_(InDestNameBytes) LPWSTR Name,
_In_ DWORD InDestNameBytes,
_Out_opt_ DWORD *OutDestNameBytes);
void
NciInit();
void
NciCleanup();

View File

@ -160,6 +160,7 @@
<ItemGroup>
<ClCompile Include="api.c" />
<ClCompile Include="namespace.c" />
<ClCompile Include="nci.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -36,5 +36,8 @@
<ClCompile Include="namespace.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="nci.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

33
api/nci.c Normal file
View File

@ -0,0 +1,33 @@
/* SPDX-License-Identifier: GPL-2.0
*
* Copyright (C) 2018-2020 WireGuard LLC. All Rights Reserved.
*/
#include "api.h"
static HMODULE NciModule;
_Return_type_success_(return == 0) DWORD (WINAPI *NciSetConnectionName)(_In_ LPCGUID Guid, _In_z_ LPCWSTR NewName);
_Return_type_success_(return == 0) DWORD (WINAPI *NciGetConnectionName)(
_In_ LPCGUID Guid,
_Out_z_bytecap_(InDestNameBytes) LPWSTR Name,
_In_ DWORD InDestNameBytes,
_Out_opt_ DWORD *OutDestNameBytes);
void
NciInit()
{
NciModule = LoadLibraryW(L"nci.dll");
if (!NciModule)
return;
NciSetConnectionName = (DWORD (WINAPI *)(LPCGUID, LPCWSTR))GetProcAddress(NciModule, "NciSetConnectionName");
NciGetConnectionName = (DWORD (WINAPI *)(LPCGUID, LPWSTR, DWORD, DWORD *))GetProcAddress(NciModule, "NciGetConnectionName");
}
void
NciCleanup()
{
if (NciModule)
FreeLibrary(NciModule);
}