diff options
| author | Mitchell <mitch@riedstra.dev> | 2021-01-12 19:56:14 -0500 |
|---|---|---|
| committer | Mitchell <mitch@riedstra.dev> | 2021-01-12 19:56:14 -0500 |
| commit | fde64077cdd85f7a7b989fef320bf7fa3826a01d (patch) | |
| tree | b414e7e0ecdccd9f99006bd0965d52ce16de5452 /cmd/web/main.go | |
| parent | 602790e2ca33ad7f22235bf2ae548cef7db8b814 (diff) | |
| download | steam-export-fde64077cdd85f7a7b989fef320bf7fa3826a01d.tar.gz steam-export-fde64077cdd85f7a7b989fef320bf7fa3826a01d.tar.xz | |
Ignore ipv4 link local addresses
Diffstat (limited to 'cmd/web/main.go')
| -rw-r--r-- | cmd/web/main.go | 9 |
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() } } |
