diff --git a/net/netns/netns_darwin.go b/net/netns/netns_darwin.go index 55e29cc29..ac5e89d76 100644 --- a/net/netns/netns_darwin.go +++ b/net/netns/netns_darwin.go @@ -92,7 +92,9 @@ func getInterfaceIndex(logf logger.Logf, netMon *netmon.Monitor, address string) // If the address doesn't parse, use the default index. addr, err := parseAddress(address) if err != nil { - logf("[unexpected] netns: error parsing address %q: %v", address, err) + if err != errUnspecifiedHost { + logf("[unexpected] netns: error parsing address %q: %v", address, err) + } return defaultIdx() } diff --git a/net/netns/netns_dw.go b/net/netns/netns_dw.go index bf654666f..f92ba9462 100644 --- a/net/netns/netns_dw.go +++ b/net/netns/netns_dw.go @@ -6,16 +6,22 @@ package netns import ( + "errors" "net" "net/netip" ) +var errUnspecifiedHost = errors.New("unspecified host") + func parseAddress(address string) (addr netip.Addr, err error) { host, _, err := net.SplitHostPort(address) if err != nil { // error means the string didn't contain a port number, so use the string directly host = address } + if host == "" { + return addr, errUnspecifiedHost + } return netip.ParseAddr(host) } diff --git a/net/netns/netns_windows.go b/net/netns/netns_windows.go index c78001560..afbda0f47 100644 --- a/net/netns/netns_windows.go +++ b/net/netns/netns_windows.go @@ -102,7 +102,9 @@ func controlC(logf logger.Logf, network, address string, c syscall.RawConn) (err } } } else { - logf("[unexpected] netns: error parsing address %q: %v", address, err) + if err != errUnspecifiedHost { + logf("[unexpected] netns: error parsing address %q: %v", address, err) + } ifaceIdxV4, ifaceIdxV6 = defIfaceIdxV4, defIfaceIdxV6 } } else {