diff --git a/server.go b/server.go index f0c61fe..1ed0f8d 100644 --- a/server.go +++ b/server.go @@ -110,7 +110,9 @@ func validateAddr(addr string) (string, error) { } // see if we're dealing with a hostname - hostnames, _ := net.LookupHost(rawHost) + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) + defer cancel() + hostnames, _ := net.DefaultResolver.LookupHost(ctx, rawHost) if len(hostnames) > 0 { if rawHost == "::1" { // special case for localhost diff --git a/server_internal_test.go b/server_internal_test.go index dc46aae..4a5bae3 100644 --- a/server_internal_test.go +++ b/server_internal_test.go @@ -150,6 +150,11 @@ func TestValidateAddr(t *testing.T) { addr: "2001:db8:3333:4444:5555:6666:7777:8888:389", expected: "2001:db8:3333:4444:5555:6666:7777:8888:389", }, + { + name: "valid-IPv6-literal", + addr: "[2001:db8:3333:4444:5555:6666:7777:8888]:389", + expected: "[2001:db8:3333:4444:5555:6666:7777:8888]:389", + }, { name: "valid-IPv6-localhost-without-brackets", addr: "::1:389",