diff --git a/internal/host/host.go b/internal/host/host.go index 5a6caba09d1..9abc0345b89 100644 --- a/internal/host/host.go +++ b/internal/host/host.go @@ -50,20 +50,16 @@ func Extract(hostPort string, lis net.Listener) (string, error) { if err != nil { return "", err } - minIndex := int(^uint(0) >> 1) - ips := make([]net.IP, 0) + ips := make([]net.IP, 0, 1) for _, iface := range ifaces { - if (iface.Flags & net.FlagUp) == 0 { - continue - } - if iface.Index >= minIndex && len(ips) != 0 { + if iface.Flags&net.FlagUp == 0 { continue } addrs, err := iface.Addrs() if err != nil { continue } - for i, rawAddr := range addrs { + for _, rawAddr := range addrs { var ip net.IP switch addr := rawAddr.(type) { case *net.IPAddr: @@ -74,19 +70,15 @@ func Extract(hostPort string, lis net.Listener) (string, error) { continue } if isValidIP(ip.String()) { - minIndex = iface.Index - if i == 0 { - ips = make([]net.IP, 0, 1) - } ips = append(ips, ip) if ip.To4() != nil { break } } } - } - if len(ips) != 0 { - return net.JoinHostPort(ips[len(ips)-1].String(), port), nil + if len(ips) != 0 { + return net.JoinHostPort(ips[len(ips)-1].String(), port), nil + } } return "", nil }