summaryrefslogtreecommitdiffhomepage
path: root/tun/wintun/nci/nci_windows.go
blob: 9dc669938c74c9bbd91a33d789fc1500a62b4c5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
}