mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2024-11-22 23:33:09 +01:00
wintun: also set friendly name after setting interface name
This commit is contained in:
parent
333de75370
commit
eb786cd7c1
@ -563,19 +563,34 @@ func (wintun *Wintun) InterfaceName() (string, error) {
|
|||||||
|
|
||||||
// SetInterfaceName sets name of the Wintun interface.
|
// SetInterfaceName sets name of the Wintun interface.
|
||||||
func (wintun *Wintun) SetInterfaceName(ifname string) error {
|
func (wintun *Wintun) SetInterfaceName(ifname string) error {
|
||||||
|
netRegKey, err := registry.OpenKey(registry.LOCAL_MACHINE, wintun.netRegKeyName(), registry.SET_VALUE)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Network-specific registry key open failed: %v", err)
|
||||||
|
}
|
||||||
|
defer netRegKey.Close()
|
||||||
|
err = netRegKey.SetStringValue("Name", ifname)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
deviceRegKey, err := registry.OpenKey(registry.LOCAL_MACHINE, wintun.deviceRegKeyName(), registry.SET_VALUE)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Device-level registry key open failed: %v", err)
|
||||||
|
}
|
||||||
|
defer deviceRegKey.Close()
|
||||||
|
err = deviceRegKey.SetStringValue("DeviceDesc", deviceTypeName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = deviceRegKey.SetStringValue("FriendlyName", deviceTypeName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
// We have to tell the various runtime COM services about the new name too. We ignore the
|
// We have to tell the various runtime COM services about the new name too. We ignore the
|
||||||
// error because netshell isn't available on servercore.
|
// error because netshell isn't available on servercore.
|
||||||
// TODO: netsh.exe falls back to NciSetConnection in this case. If somebody complains, maybe
|
// TODO: netsh.exe falls back to NciSetConnection in this case. If somebody complains, maybe
|
||||||
// we should do the same.
|
// we should do the same.
|
||||||
netshell.HrRenameConnection(&wintun.cfgInstanceID, windows.StringToUTF16Ptr(ifname))
|
netshell.HrRenameConnection(&wintun.cfgInstanceID, windows.StringToUTF16Ptr(ifname))
|
||||||
|
return nil
|
||||||
// Set the interface name. The above line should have done this too, but in case it failed, we force it.
|
|
||||||
key, err := registry.OpenKey(registry.LOCAL_MACHINE, wintun.netRegKeyName(), registry.SET_VALUE)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Network-specific registry key open failed: %v", err)
|
|
||||||
}
|
|
||||||
defer key.Close()
|
|
||||||
return key.SetStringValue("Name", ifname)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// netRegKeyName returns the interface-specific network registry key name.
|
// netRegKeyName returns the interface-specific network registry key name.
|
||||||
|
Loading…
Reference in New Issue
Block a user