vivekkoya
1 month ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
3 additions and
13 deletions
-
weed/util/network.go
|
|
|
@ -15,18 +15,14 @@ func DetectedHostAddress() string { |
|
|
|
return "" |
|
|
|
} |
|
|
|
|
|
|
|
if v4Address := selectIpV4(netInterfaces, true); v4Address != "" { |
|
|
|
if v4Address := selectIpV4(netInterfaces); v4Address != "" { |
|
|
|
return v4Address |
|
|
|
} |
|
|
|
|
|
|
|
if v6Address := selectIpV4(netInterfaces, false); v6Address != "" { |
|
|
|
return v6Address |
|
|
|
} |
|
|
|
|
|
|
|
return "localhost" |
|
|
|
} |
|
|
|
|
|
|
|
func selectIpV4(netInterfaces []net.Interface, isIpV4 bool) string { |
|
|
|
func selectIpV4(netInterfaces []net.Interface) string { |
|
|
|
for _, netInterface := range netInterfaces { |
|
|
|
if (netInterface.Flags & net.FlagUp) == 0 { |
|
|
|
continue |
|
|
|
@ -38,15 +34,9 @@ func selectIpV4(netInterfaces []net.Interface, isIpV4 bool) string { |
|
|
|
|
|
|
|
for _, a := range addrs { |
|
|
|
if ipNet, ok := a.(*net.IPNet); ok && !ipNet.IP.IsLoopback() { |
|
|
|
if isIpV4 { |
|
|
|
if ipNet.IP.To4() != nil { |
|
|
|
return ipNet.IP.String() |
|
|
|
} |
|
|
|
} else { |
|
|
|
if ipNet.IP.To16() != nil { |
|
|
|
if ipNet.IP.To4() != nil && ipNet.IP.To16() == nil || ipNet.IP.To16() != nil && ipNet.IP.To4() == nil{ |
|
|
|
return ipNet.IP.String() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|