diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2023-12-24 12:32:37 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-24 12:32:37 -0800 |
| commit | 9af2049dfe65e61a2e553e9269cbf49b998c9ea5 (patch) | |
| tree | dc2179cbb649cdb6400ed53d244e2a918e3ab87d | |
| parent | c6b1dc7058a60c5aa4711fb70bdc7f444478e8d6 (diff) | |
| download | seaweedfs-origin/revert-5134-patch-1.tar.xz seaweedfs-origin/revert-5134-patch-1.zip | |
Revert "Update network.go since To16 converts the IP address ip up to a 16-byte representation. If ip is not an IP address (it is the wrong length), To16 returns nil. (#5134)"origin/revert-5134-patch-1
This reverts commit 838578b55f138d98d9d2b3a0246a7fbb12fd379c.
| -rw-r--r-- | weed/util/network.go | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/weed/util/network.go b/weed/util/network.go index b7036377f..69559b5f0 100644 --- a/weed/util/network.go +++ b/weed/util/network.go @@ -15,13 +15,18 @@ func DetectedHostAddress() string { return "" } - if v4Address := selectIpV4(netInterfaces); v4Address != "" { + if v4Address := selectIpV4(netInterfaces, true); v4Address != "" { return v4Address } + if v6Address := selectIpV4(netInterfaces, false); v6Address != "" { + return v6Address + } + return "localhost" } -func selectIpV4(netInterfaces []net.Interface) string { + +func selectIpV4(netInterfaces []net.Interface, isIpV4 bool) string { for _, netInterface := range netInterfaces { if (netInterface.Flags & net.FlagUp) == 0 { continue @@ -33,9 +38,15 @@ func selectIpV4(netInterfaces []net.Interface) 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 { return ipNet.IP.String() } + } } } } |
