diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-07-19 13:51:56 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-07-19 14:01:34 +0200 |
commit | 3341e2d4448e51152c2e919f0a694c5667fa91dd (patch) | |
tree | a94c09626b724138bb2d8092541221ae4bf3e75a /tun/wintun/wintun_windows.go | |
parent | 1b550f658325d7525cc4357024352599c6796d32 (diff) |
tun: windows: get rid of retry logic
Things work fine on Windows 8.
Diffstat (limited to 'tun/wintun/wintun_windows.go')
-rw-r--r-- | tun/wintun/wintun_windows.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/tun/wintun/wintun_windows.go b/tun/wintun/wintun_windows.go index e8eadf5..88d565d 100644 --- a/tun/wintun/wintun_windows.go +++ b/tun/wintun/wintun_windows.go @@ -612,21 +612,25 @@ func (wintun *Wintun) deviceData() (setupapi.DevInfo, *setupapi.DevInfoData, err return 0, nil, windows.ERROR_OBJECT_NOT_FOUND } -// NdisFileName returns the Wintun NDIS device object name. -func (wintun *Wintun) NdisFileName() (string, error) { +// AdapterHandle returns a handle to the adapter device object. +func (wintun *Wintun) AdapterHandle() (windows.Handle, error) { key, err := registry.OpenKey(registry.LOCAL_MACHINE, wintun.netRegKeyName(), registry.QUERY_VALUE) if err != nil { - return "", fmt.Errorf("Network-specific registry key open failed: %v", err) + return windows.InvalidHandle, fmt.Errorf("Network-specific registry key open failed: %v", err) } defer key.Close() // Get the interface name. pnpInstanceID, err := registryEx.GetStringValue(key, "PnPInstanceId") if err != nil { - return "", fmt.Errorf("PnpInstanceId registry key read failed: %v", err) + return windows.InvalidHandle, fmt.Errorf("PnPInstanceId registry key read failed: %v", err) } mangledPnpNode := strings.ReplaceAll(fmt.Sprintf("%s\\{cac88484-7515-4c03-82e6-71a87abac361}", pnpInstanceID), "\\", "#") - return fmt.Sprintf("\\\\.\\Global\\%s", mangledPnpNode), nil + handle, err := windows.CreateFile(windows.StringToUTF16Ptr(fmt.Sprintf("\\\\.\\Global\\%s", mangledPnpNode)), windows.GENERIC_READ|windows.GENERIC_WRITE, 0, nil, windows.OPEN_EXISTING, 0, 0) + if err != nil { + return windows.InvalidHandle, fmt.Errorf("CreateFile on mangled PnPInstanceId path failed: %v", err) + } + return handle, nil } // GUID returns the GUID of the interface. |