summaryrefslogtreecommitdiffhomepage
path: root/tun/wintun/nci/nci_windows.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-08-21 08:40:44 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-08-21 09:16:12 +0200
commit68fea631d8e97aa7395b944916e569cf66553e73 (patch)
tree5ebd8d7c0227fd1b59cf961328814335f024060d /tun/wintun/nci/nci_windows.go
parentef23100a4f86948e0466dce980d8604ad95f13df (diff)
wintun: use nci.dll directly instead of buggy netshell
Diffstat (limited to 'tun/wintun/nci/nci_windows.go')
-rw-r--r--tun/wintun/nci/nci_windows.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/tun/wintun/nci/nci_windows.go b/tun/wintun/nci/nci_windows.go
new file mode 100644
index 0000000..9dc6699
--- /dev/null
+++ b/tun/wintun/nci/nci_windows.go
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: MIT
+ *
+ * Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
+ */
+
+package nci
+
+import "golang.org/x/sys/windows"
+
+//sys nciSetConnectionName(guid *windows.GUID, newName *uint16) (ret error) = nci.NciSetConnectionName
+//sys nciGetConnectionName(guid *windows.GUID, destName *uint16, inDestNameBytes uint32, outDestNameBytes *uint32) (ret error) = nci.NciGetConnectionName
+
+func SetConnectionName(guid *windows.GUID, newName string) error {
+ newName16, err := windows.UTF16PtrFromString(newName)
+ if err != nil {
+ return err
+ }
+ return nciSetConnectionName(guid, newName16)
+}
+
+func ConnectionName(guid *windows.GUID) (string, error) {
+ var name [0x400]uint16
+ err := nciGetConnectionName(guid, &name[0], uint32(len(name)*2), nil)
+ if err != nil {
+ return "", err
+ }
+ return windows.UTF16ToString(name[:]), nil
+}