1
0
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:
icylight 2022-08-31 21:35:59 +08:00 committed by GitHub
parent 20c2425c18
commit cbfb6db9cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
}
}
}