fix(internal/host): Extract can't return the minium index ip (#2298)

* fix(internal/host): Extract can't return the minium index ip

* rollback

* fix index
pull/2312/head
icylight 2 years ago committed by GitHub
parent 20c2425c18
commit cbfb6db9cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      internal/host/host.go

@ -50,16 +50,13 @@ func Extract(hostPort string, lis net.Listener) (string, error) {
if err != nil {
return "", err
}
lowest := int(^uint(0) >> 1)
minIndex := int(^uint(0) >> 1)
var result net.IP
for _, iface := range ifaces {
if (iface.Flags & net.FlagUp) == 0 {
continue
}
if iface.Index < lowest || result == nil {
lowest = iface.Index
}
if result != nil {
if iface.Index >= minIndex && result != nil {
continue
}
addrs, err := iface.Addrs()
@ -77,7 +74,9 @@ func Extract(hostPort string, lis net.Listener) (string, error) {
continue
}
if isValidIP(ip.String()) {
minIndex = iface.Index
result = ip
break
}
}
}

Loading…
Cancel
Save