diff --git a/src/net/lookup.go b/src/net/lookup.go index a7ceee823f1..9008322dc5a 100644 --- a/src/net/lookup.go +++ b/src/net/lookup.go @@ -123,6 +123,9 @@ func lookupIPDeadline(host string, deadline time.Time) (addrs []IPAddr, err erro // LookupPort looks up the port for the given network and service. func LookupPort(network, service string) (port int, err error) { + if n, i, ok := dtoi(service, 0); ok && i == len(service) { + return n, nil + } return lookupPort(network, service) } diff --git a/src/net/port_test.go b/src/net/port_test.go index 2dacd975e7a..258a5bda48f 100644 --- a/src/net/port_test.go +++ b/src/net/port_test.go @@ -27,6 +27,7 @@ var portTests = []struct { {"tcp", "time", 37, true}, {"tcp", "domain", 53, true}, {"tcp", "finger", 79, true}, + {"tcp", "42", 42, true}, {"udp", "echo", 7, true}, {"udp", "tftp", 69, true}, @@ -36,6 +37,7 @@ var portTests = []struct { {"udp", "ntp", 123, true}, {"udp", "snmp", 161, true}, {"udp", "syslog", 514, true}, + {"udp", "42", 42, true}, {"--badnet--", "zzz", 0, false}, {"tcp", "--badport--", 0, false},