aboutsummaryrefslogtreecommitdiff
path: root/weed/util
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-04-09 00:26:24 -0700
committerChris Lu <chris.lu@gmail.com>2020-04-09 00:26:24 -0700
commit59f40e202783dae6c83421e278608eeda7a97dbf (patch)
treef25a8ff459f4905e732fa05943c81e704b87c4d0 /weed/util
parentf6a7e79dc370dfb2e3fe5bff6a380afde95b9a7f (diff)
downloadseaweedfs-59f40e202783dae6c83421e278608eeda7a97dbf.tar.xz
seaweedfs-59f40e202783dae6c83421e278608eeda7a97dbf.zip
volume: best effort to detect ip address
fix https://github.com/chrislusf/seaweedfs/issues/1264
Diffstat (limited to 'weed/util')
-rw-r--r--weed/util/network.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/weed/util/network.go b/weed/util/network.go
new file mode 100644
index 000000000..7108cfea6
--- /dev/null
+++ b/weed/util/network.go
@@ -0,0 +1,25 @@
+package util
+
+import (
+ "net"
+
+ "github.com/chrislusf/seaweedfs/weed/glog"
+)
+
+func DetectedHostAddress() string {
+ addrs, err := net.InterfaceAddrs()
+ if err != nil {
+ glog.V(0).Infof("failed to detect ip address: %v", err)
+ return ""
+ }
+
+ for _, a := range addrs {
+ if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
+ if ipnet.IP.To4() != nil {
+ return ipnet.IP.String()
+ }
+ }
+ }
+
+ return "localhost"
+}