aboutsummaryrefslogtreecommitdiffstats
path: root/tun/wintun
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-07-19 13:51:56 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-07-19 14:01:34 +0200
commit3341e2d4448e51152c2e919f0a694c5667fa91dd (patch)
treea94c09626b724138bb2d8092541221ae4bf3e75a /tun/wintun
parenttun: windows: use specific IOCTL code (diff)
downloadwireguard-go-3341e2d4448e51152c2e919f0a694c5667fa91dd.tar.xz
wireguard-go-3341e2d4448e51152c2e919f0a694c5667fa91dd.zip
tun: windows: get rid of retry logic
Things work fine on Windows 8.
Diffstat (limited to 'tun/wintun')
-rw-r--r--tun/wintun/wintun_windows.go14
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.