summaryrefslogtreecommitdiffhomepage
path: root/tun/wintun/netshell/netshell_windows.go
blob: 3122d87552aeeb81dc005894077e2f5a240488e7 (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
29
30
31
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
}