mirror of
https://github.com/golang/go
synced 2024-11-23 20:00:04 -07:00
net: restore LookupPort for integer strings
This worked in Go 1.4 but was lost in the "pure Go" lookup routines substituted late in the Go 1.5 cycle. Fixes #12263. Change-Id: I77ec9d97cd8e67ace99d6ac965e5bc16c151ba83 Reviewed-on: https://go-review.googlesource.com/13915 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
8261c887aa
commit
35365b97f1
@ -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.
|
// LookupPort looks up the port for the given network and service.
|
||||||
func LookupPort(network, service string) (port int, err error) {
|
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)
|
return lookupPort(network, service)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ var portTests = []struct {
|
|||||||
{"tcp", "time", 37, true},
|
{"tcp", "time", 37, true},
|
||||||
{"tcp", "domain", 53, true},
|
{"tcp", "domain", 53, true},
|
||||||
{"tcp", "finger", 79, true},
|
{"tcp", "finger", 79, true},
|
||||||
|
{"tcp", "42", 42, true},
|
||||||
|
|
||||||
{"udp", "echo", 7, true},
|
{"udp", "echo", 7, true},
|
||||||
{"udp", "tftp", 69, true},
|
{"udp", "tftp", 69, true},
|
||||||
@ -36,6 +37,7 @@ var portTests = []struct {
|
|||||||
{"udp", "ntp", 123, true},
|
{"udp", "ntp", 123, true},
|
||||||
{"udp", "snmp", 161, true},
|
{"udp", "snmp", 161, true},
|
||||||
{"udp", "syslog", 514, true},
|
{"udp", "syslog", 514, true},
|
||||||
|
{"udp", "42", 42, true},
|
||||||
|
|
||||||
{"--badnet--", "zzz", 0, false},
|
{"--badnet--", "zzz", 0, false},
|
||||||
{"tcp", "--badport--", 0, false},
|
{"tcp", "--badport--", 0, false},
|
||||||
|
Loading…
Reference in New Issue
Block a user