diff options
author | Simon Rozman <simon@rozman.si> | 2020-07-07 15:32:06 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-10-30 16:50:58 +0100 |
commit | 3fa45fec719947f4659846e53e84381eca5236bb (patch) | |
tree | 27496fc2af62d0d7c7d338a5b3cafef73c6ef342 /api | |
parent | api: port tun\wintun\namespace_windows.go from wireguard-go (diff) | |
download | wintun-3fa45fec719947f4659846e53e84381eca5236bb.tar.xz wintun-3fa45fec719947f4659846e53e84381eca5236bb.zip |
api: port nci package from wireguard-go
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'api')
-rw-r--r-- | api/api.c | 2 | ||||
-rw-r--r-- | api/api.h | 15 | ||||
-rw-r--r-- | api/api.vcxproj | 1 | ||||
-rw-r--r-- | api/api.vcxproj.filters | 3 | ||||
-rw-r--r-- | api/nci.c | 33 |
5 files changed, 54 insertions, 0 deletions
@@ -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; } @@ -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(); diff --git a/api/api.vcxproj b/api/api.vcxproj index 0b8c969..a5bcd11 100644 --- a/api/api.vcxproj +++ b/api/api.vcxproj @@ -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"> diff --git a/api/api.vcxproj.filters b/api/api.vcxproj.filters index c68297c..e7cba38 100644 --- a/api/api.vcxproj.filters +++ b/api/api.vcxproj.filters @@ -36,5 +36,8 @@ <ClCompile Include="namespace.c"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="nci.c"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> </Project>
\ No newline at end of file diff --git a/api/nci.c b/api/nci.c new file mode 100644 index 0000000..c479f50 --- /dev/null +++ b/api/nci.c @@ -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); +} |