From cbfb6db9cf68df3919049f6220096adf83c982e6 Mon Sep 17 00:00:00 2001 From: icylight <408209435@qq.com> Date: Wed, 31 Aug 2022 21:35:59 +0800 Subject: [PATCH] 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 --- internal/host/host.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/internal/host/host.go b/internal/host/host.go index d5cc7ffa3..bf204eede 100644 --- a/internal/host/host.go +++ b/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 } } }