diff --git a/pkg/port/parse.go b/pkg/port/parse.go index cb744d52a..6646d4fd0 100644 --- a/pkg/port/parse.go +++ b/pkg/port/parse.go @@ -2,6 +2,7 @@ package port import ( "fmt" + "net" "strconv" "strings" ) @@ -36,7 +37,7 @@ func toAddress(host, port string) (Address, error) { return Address{ Protocol: "tcp", - Address: host + ":" + port, + Address: net.JoinHostPort(host, port), }, nil } diff --git a/pkg/port/parse_test.go b/pkg/port/parse_test.go index 38698d68b..8f30d1e43 100644 --- a/pkg/port/parse_test.go +++ b/pkg/port/parse_test.go @@ -151,7 +151,13 @@ func TestToAddress_TCP(t *testing.T) { Address{Protocol: protoTCP, Address: "database.internal:5432"}, }, {"short hostname", "db", "5432", Address{Protocol: protoTCP, Address: "db:5432"}}, - {"IPv6 address", "::1", "8080", Address{Protocol: protoTCP, Address: "::1:8080"}}, + {"IPv6 address", "::1", "8080", Address{Protocol: protoTCP, Address: "[::1]:8080"}}, + { + "IPv6 host brackets for listen", + "fe80::1", + "443", + Address{Protocol: protoTCP, Address: "[fe80::1]:443"}, + }, } for _, tt := range tests {