wintun: simplify rename logic
This commit is contained in:
parent
da28a3e9f3
commit
e862131d3c
|
@ -568,12 +568,8 @@ func (wintun *Wintun) InterfaceName() (string, error) {
|
||||||
func (wintun *Wintun) SetInterfaceName(ifname string) error {
|
func (wintun *Wintun) SetInterfaceName(ifname string) error {
|
||||||
const maxSuffix = 1000
|
const maxSuffix = 1000
|
||||||
availableIfname := ifname
|
availableIfname := ifname
|
||||||
setloop:
|
|
||||||
for i := 0; ; i++ {
|
for i := 0; ; i++ {
|
||||||
err := nci.SetConnectionName(&wintun.cfgInstanceID, availableIfname)
|
err := nci.SetConnectionName(&wintun.cfgInstanceID, availableIfname)
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err == windows.ERROR_DUP_NAME {
|
if err == windows.ERROR_DUP_NAME {
|
||||||
duplicateGuid, err2 := iphlpapi.InterfaceGUIDFromAlias(availableIfname)
|
duplicateGuid, err2 := iphlpapi.InterfaceGUIDFromAlias(availableIfname)
|
||||||
if err2 == nil {
|
if err2 == nil {
|
||||||
|
@ -589,13 +585,16 @@ setloop:
|
||||||
if err2 == nil {
|
if err2 == nil {
|
||||||
err = nci.SetConnectionName(&wintun.cfgInstanceID, availableIfname)
|
err = nci.SetConnectionName(&wintun.cfgInstanceID, availableIfname)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
break setloop
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
if i > maxSuffix || err != windows.ERROR_DUP_NAME {
|
if i > maxSuffix || err != windows.ERROR_DUP_NAME {
|
||||||
return fmt.Errorf("NciSetConnectionName failed: %v", err)
|
return fmt.Errorf("NciSetConnectionName failed: %v", err)
|
||||||
|
|
Loading…
Reference in a new issue