aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvivekkoya <67130044+vivekkoya@users.noreply.github.com>2023-12-23 15:01:57 -0800
committerGitHub <noreply@github.com>2023-12-23 15:01:57 -0800
commit838578b55f138d98d9d2b3a0246a7fbb12fd379c (patch)
treef631bebf33318eb0ec078fc846202fc6aa283249
parent97236389e8a7e72680c4508cdc1db3746dfd8c76 (diff)
downloadseaweedfs-838578b55f138d98d9d2b3a0246a7fbb12fd379c.tar.xz
seaweedfs-838578b55f138d98d9d2b3a0246a7fbb12fd379c.zip
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)
-rw-r--r--weed/util/network.go15
1 files changed, 2 insertions, 13 deletions
diff --git a/weed/util/network.go b/weed/util/network.go
index 69559b5f0..b7036377f 100644
--- a/weed/util/network.go
+++ b/weed/util/network.go
@@ -15,18 +15,13 @@ 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 +33,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 {
return ipNet.IP.String()
}
- }
}
}
}