aboutsummaryrefslogtreecommitdiffstats
path: root/api/adapter.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-11-02 00:13:55 +0100
committerSimon Rozman <simon@rozman.si>2020-11-02 12:38:37 +0100
commit7f35f0dbab5237bef45a7cc93b3faf6f21296974 (patch)
treec6d555534f17a320c1334a3316cbe4b0ea047936 /api/adapter.c
parentapi: simplify and unify error messages (diff)
downloadwintun-7f35f0dbab5237bef45a7cc93b3faf6f21296974.tar.xz
wintun-7f35f0dbab5237bef45a7cc93b3faf6f21296974.zip
api: map cr errors to win32 errors
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'api/adapter.c')
-rw-r--r--api/adapter.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/api/adapter.c b/api/adapter.c
index 159b244..7db8023 100644
--- a/api/adapter.c
+++ b/api/adapter.c
@@ -174,26 +174,22 @@ static WINTUN_STATUS
GetDeviceObject(_In_opt_z_ const WCHAR *InstanceId, _Out_ HANDLE *Handle)
{
ULONG InterfacesLen;
- DWORD Result = CM_Get_Device_Interface_List_SizeW(
- &InterfacesLen, (GUID *)&GUID_DEVINTERFACE_NET, (DEVINSTID_W)InstanceId, CM_GET_DEVICE_INTERFACE_LIST_PRESENT);
- if (Result != CR_SUCCESS)
- {
- LOG(WINTUN_LOG_ERR, L"Failed to query associated instances size");
- return ERROR_GEN_FAILURE;
- }
+ DWORD Result = CM_MapCrToWin32Err(CM_Get_Device_Interface_List_SizeW(
+ &InterfacesLen, (GUID *)&GUID_DEVINTERFACE_NET, (DEVINSTID_W)InstanceId, CM_GET_DEVICE_INTERFACE_LIST_PRESENT), ERROR_GEN_FAILURE);
+ if (Result != ERROR_SUCCESS)
+ return LOG_ERROR(L"Failed to query associated instances size", Result);
WCHAR *Interfaces = HeapAlloc(ModuleHeap, 0, InterfacesLen * sizeof(WCHAR));
if (!Interfaces)
return LOG(WINTUN_LOG_ERR, L"Out of memory"), ERROR_OUTOFMEMORY;
- Result = CM_Get_Device_Interface_ListW(
+ Result = CM_MapCrToWin32Err(CM_Get_Device_Interface_ListW(
(GUID *)&GUID_DEVINTERFACE_NET,
(DEVINSTID_W)InstanceId,
Interfaces,
InterfacesLen,
- CM_GET_DEVICE_INTERFACE_LIST_PRESENT);
- if (Result != CR_SUCCESS)
+ CM_GET_DEVICE_INTERFACE_LIST_PRESENT), ERROR_GEN_FAILURE);
+ if (Result != ERROR_SUCCESS)
{
- LOG(WINTUN_LOG_ERR, L"Failed to get associated instances");
- Result = ERROR_GEN_FAILURE;
+ LOG_ERROR(L"Failed to get associated instances", Result);
goto cleanupBuf;
}
*Handle = CreateFileW(