tun: windows: get rid of retry logic
Things work fine on Windows 8.
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user