summaryrefslogtreecommitdiffhomepage
path: root/tun/wintun
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-05-24 09:28:50 +0200
committerSimon Rozman <simon@rozman.si>2019-05-24 09:29:57 +0200
commit6a0a3a54067182aee4c2cb4c7ef7ac5aaf2fd961 (patch)
treef2278f9c28d443d198e2fdb7819753a4d9d5b682 /tun/wintun
parent8fdcf5ee30d9576b5ddb163180f5d5506a349eea (diff)
wintun: revise GetInterface()
- Make foreign interface found error numeric to ease condition detection. - Update GetInterface() documentation. - Make tun.CreateTUN() quit when foreign interface found before attempting to create a Wintun interface with a duplicate name. Creation is futile. Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'tun/wintun')
-rw-r--r--tun/wintun/wintun_windows.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/tun/wintun/wintun_windows.go b/tun/wintun/wintun_windows.go
index aea4ad1..7b99a50 100644
--- a/tun/wintun/wintun_windows.go
+++ b/tun/wintun/wintun_windows.go
@@ -89,8 +89,9 @@ func makeWintun(deviceInfoSet setupapi.DevInfo, deviceInfoData *setupapi.DevInfo
// optional and can be 0. If a specific top-level window is not required, set
// hwndParent to 0.
//
-// Function returns interface if found, or nil otherwise. If the interface is
-// found but not Wintun-class, the function returns interface and an error.
+// Function returns interface if found, or windows.ERROR_OBJECT_NOT_FOUND
+// otherwise. If the interface is found but not Wintun-class, the function
+// returns windows.ERROR_ALREADY_EXISTS.
//
func GetInterface(ifname string, hwndParent uintptr) (*Wintun, error) {
// Create a list of network devices.
@@ -164,7 +165,7 @@ func GetInterface(ifname string, hwndParent uintptr) (*Wintun, error) {
}
// This interface is not using Wintun driver.
- return nil, errors.New("Foreign network interface with the same name exists")
+ return nil, windows.ERROR_ALREADY_EXISTS
}
}