aboutsummaryrefslogtreecommitdiff
path: root/cmd/web
diff options
context:
space:
mode:
authorMitchell <mitch@riedstra.dev>2021-01-12 19:56:14 -0500
committerMitchell <mitch@riedstra.dev>2021-01-12 19:56:14 -0500
commitfde64077cdd85f7a7b989fef320bf7fa3826a01d (patch)
treeb414e7e0ecdccd9f99006bd0965d52ce16de5452 /cmd/web
parent602790e2ca33ad7f22235bf2ae548cef7db8b814 (diff)
downloadsteam-export-fde64077cdd85f7a7b989fef320bf7fa3826a01d.tar.gz
steam-export-fde64077cdd85f7a7b989fef320bf7fa3826a01d.tar.xz
Ignore ipv4 link local addresses
Diffstat (limited to 'cmd/web')
-rw-r--r--cmd/web/install.go2
-rw-r--r--cmd/web/main.go9
2 files changed, 7 insertions, 4 deletions
diff --git a/cmd/web/install.go b/cmd/web/install.go
index d9a2379..8cf8b66 100644
--- a/cmd/web/install.go
+++ b/cmd/web/install.go
@@ -70,7 +70,7 @@ func installHttp(u string) error {
go func() {
err = Lib.Extract(rdr)
if err != nil {
- Logger.Printf("Installer: extracting %w", err)
+ Logger.Printf("Installer: extracting %s", err)
}
resp.Body.Close()
}()
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()
}
}