mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-14 02:33:03 +02:00
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
This commit is contained in:
parent
20c2425c18
commit
cbfb6db9cf
@ -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…
Reference in New Issue
Block a user