taptun: fix adapter detection on windows for newer versions of taptun driver

This commit is contained in:
Patrick Mackinlay 2023-04-25 14:45:43 +07:00
parent 4bc6a8d0e6
commit 5b567d4a37
2 changed files with 20 additions and 8 deletions

View file

@ -51,6 +51,13 @@
/* obsoletes TAP_WIN_IOCTL_CONFIG_POINT_TO_POINT */
#define TAP_WIN_IOCTL_CONFIG_TUN TAP_WIN_CONTROL_CODE (10, METHOD_BUFFERED)
/* Control whether 802.1Q headers are added for priority */
#define TAP_WIN_IOCTL_PRIORITY_BEHAVIOR TAP_WIN_CONTROL_CODE (11, METHOD_BUFFERED)
#define TAP_PRIORITY_BEHAVIOR_NOPRIORITY 0
#define TAP_PRIORITY_BEHAVIOR_ENABLED 1
#define TAP_PRIORITY_BEHAVIOR_ADDALWAYS 2
#define TAP_PRIORITY_BEHAVIOR_MAX 2
/*
* =================
* Registry keys

View file

@ -293,16 +293,21 @@ static std::vector<std::wstring> get_tap_adapters()
// check if the ComponentId value indicates a TAP-Windows adapter
if (RegQueryValueExW(unit_key, L"ComponentId", NULL, &data_type, LPBYTE(component_id), &component_id_len) == ERROR_SUCCESS
&& data_type == REG_SZ
&& safe_string(component_id, component_id_len) == L"" PRODUCT_TAP_WIN_COMPONENT_ID)
&& data_type == REG_SZ)
{
WCHAR net_cfg_instance_id[MAX_PATH];
DWORD net_cfg_instance_id_len = sizeof(net_cfg_instance_id);
std::wstring const value(safe_string(component_id, component_id_len));
// add the adapter to the result
if (RegQueryValueExW(unit_key, L"NetCfgInstanceId", NULL, &data_type, LPBYTE(net_cfg_instance_id), &net_cfg_instance_id_len) == ERROR_SUCCESS
&& data_type == REG_SZ)
result.push_back(safe_string(net_cfg_instance_id, net_cfg_instance_id_len));
// some older versions may not set the "root\" prefix
if (value == L"root\\" PRODUCT_TAP_WIN_COMPONENT_ID || value == L"" PRODUCT_TAP_WIN_COMPONENT_ID)
{
WCHAR net_cfg_instance_id[MAX_PATH];
DWORD net_cfg_instance_id_len = sizeof(net_cfg_instance_id);
// add the adapter to the result
if (RegQueryValueExW(unit_key, L"NetCfgInstanceId", NULL, &data_type, LPBYTE(net_cfg_instance_id), &net_cfg_instance_id_len) == ERROR_SUCCESS
&& data_type == REG_SZ)
result.push_back(safe_string(net_cfg_instance_id, net_cfg_instance_id_len));
}
}
RegCloseKey(unit_key);