aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tunnel/winipcfg/luid.go
diff options
context:
space:
mode:
authorKay Diam <kay.diam@gmail.com>2021-03-07 17:20:24 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2021-03-07 09:26:07 -0700
commit39f3c66fde966b74d093166f7a6504b6d082735f (patch)
treecab20174a642bbbececf4fd7d59d9706eae9f054 /tunnel/winipcfg/luid.go
parentringlogger: account for ERROR_ALREADY_EXISTS returns (diff)
downloadwireguard-windows-master.tar.xz
wireguard-windows-master.zip
winipcfg: add ConvertInterfaceIndexToLUIDHEADmaster
This change can be used to easily get an access to any interface by name, e.g. iface, err := net.InterfaceByName(name) if err ! nil { return err } luid, err := winipcfg.LUIDFromIndex(uint32(iface.Index)) if err != nil { return err } Signed-off-by: Kay Diam <kay.diam@gmail.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'tunnel/winipcfg/luid.go')
-rw-r--r--tunnel/winipcfg/luid.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/tunnel/winipcfg/luid.go b/tunnel/winipcfg/luid.go
index efdf1ba4..02ba65b4 100644
--- a/tunnel/winipcfg/luid.go
+++ b/tunnel/winipcfg/luid.go
@@ -63,6 +63,17 @@ func LUIDFromGUID(guid *windows.GUID) (LUID, error) {
return luid, nil
}
+// LUIDFromIndex function converts a local index for a network interface to the locally unique identifier (LUID) for the interface.
+// https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-convertinterfaceindextoluid
+func LUIDFromIndex(index uint32) (LUID, error) {
+ var luid LUID
+ err := convertInterfaceIndexToLUID(index, &luid)
+ if err != nil {
+ return 0, err
+ }
+ return luid, nil
+}
+
// IPAddress method returns MibUnicastIPAddressRow struct that matches to provided 'ip' argument. Corresponds to GetUnicastIpAddressEntry
// (https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getunicastipaddressentry)
func (luid LUID) IPAddress(ip net.IP) (*MibUnicastIPAddressRow, error) {