From 3c5db69ffd6bf6637aca6b357ab5889568f943b6 Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Wed, 24 May 2017 00:37:39 +0530 Subject: [PATCH] Treat 0.0.0.0 as local address in --address flag (#4386) --- cmd/net.go | 5 ++++- cmd/net_test.go | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/net.go b/cmd/net.go index ba62c0d77..d846773cc 100644 --- a/cmd/net.go +++ b/cmd/net.go @@ -319,7 +319,10 @@ func CheckLocalServerAddr(serverAddr string) error { return fmt.Errorf("port number must be between 1 to 65535") } - if host != "" { + // 0.0.0.0 is a wildcard address and refers to local network + // addresses. I.e, 0.0.0.0:9000 like ":9000" refers to port + // 9000 on localhost. + if host != "" && host != net.IPv4zero.String() { isLocalHost, err := isLocalHost(host) if err != nil { return err diff --git a/cmd/net_test.go b/cmd/net_test.go index 9f2e9c9a0..f020c27f4 100644 --- a/cmd/net_test.go +++ b/cmd/net_test.go @@ -221,6 +221,7 @@ func TestCheckLocalServerAddr(t *testing.T) { }{ {":54321", nil}, {"localhost:54321", nil}, + {"0.0.0.0:9000", nil}, {"", fmt.Errorf("missing port in address")}, {"localhost", fmt.Errorf("missing port in address localhost")}, {"example.org:54321", fmt.Errorf("host in server address should be this server")},