aboutsummaryrefslogtreecommitdiff
path: root/cmd/web/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/web/main.go')
-rw-r--r--cmd/web/main.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/cmd/web/main.go b/cmd/web/main.go
index d926a20..bbb7fb6 100644
--- a/cmd/web/main.go
+++ b/cmd/web/main.go
@@ -87,14 +87,17 @@ func isLocal(addr string) bool {
}
// getHostIP attempts to guess the IP address of the current machine and
-// returns that. Simply bails at the first non loopback IP returning that.
-// not ideal but it should work well enough most of the time
+// returns that. Simply bails at the first non sane looking IP and returns it.
+// Not ideal but it should work well enough most of the time
func getHostIP() string {
iFaces, err := net.Interfaces()
if err != nil {
return "127.0.0.1"
}
+ // RFC 3927
+ _, ipv4LinkLocal, _ := net.ParseCIDR("169.254.0.0/16")
+
for _, iFace := range iFaces {
addrs, err := iFace.Addrs()
if err != nil {
@@ -107,7 +110,7 @@ func getHostIP() string {
continue
}
- if n.IP.To4() != nil && !n.IP.IsLoopback() {
+ if n.IP.To4() != nil && !n.IP.IsLoopback() && !ipv4LinkLocal.Contains(n.IP.To4()) {
return n.IP.String()
}
}