summaryrefslogtreecommitdiffhomepage
path: root/tun/wintun/netshell/netshell_windows.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-04-01 12:00:33 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-04-01 12:04:44 +0200
commitac25702eaf13bb2243f02130ae271ff600f75209 (patch)
tree44f5518abce2ed2838888504d4c751e4957e9cb3 /tun/wintun/netshell/netshell_windows.go
parent92f847483200a63193d55418381e685621b24e5c (diff)
wintun: rename device using undocumented API that netsh.exe uses
Diffstat (limited to 'tun/wintun/netshell/netshell_windows.go')
-rw-r--r--tun/wintun/netshell/netshell_windows.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/tun/wintun/netshell/netshell_windows.go b/tun/wintun/netshell/netshell_windows.go
new file mode 100644
index 0000000..cb03252
--- /dev/null
+++ b/tun/wintun/netshell/netshell_windows.go
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: MIT
+ *
+ * Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
+ */
+
+package netshell
+
+import (
+ "syscall"
+ "unsafe"
+
+ "golang.org/x/sys/windows"
+)
+
+var (
+ modnetshell = windows.NewLazySystemDLL("netshell.dll")
+ procHrRenameConnection = modnetshell.NewProc("HrRenameConnection")
+)
+
+func HrRenameConnection(guid *windows.GUID, newName *uint16) (err error) {
+ err = procHrRenameConnection.Find()
+ if err != nil {
+ // Missing from servercore, so we can't presume it's always there.
+ return
+ }
+
+ ret, _, _ := syscall.Syscall(procHrRenameConnection.Addr(), 2, uintptr(unsafe.Pointer(guid)), uintptr(unsafe.Pointer(newName)), 0)
+ if ret != 0 {
+ err = syscall.Errno(ret)
+ }
+ return
+}