mirror of https://github.com/golang/go.git
net: make LookupPort with empty service mean 0
Fixes #13610 Change-Id: I9c8f924dc1ad515a9697291e981ece34fdbec8b7 Reviewed-on: https://go-review.googlesource.com/17755 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
2190750ce1
commit
5a88e54fda
|
|
@ -123,6 +123,11 @@ 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 service == "" {
|
||||
// Lock in the legacy behavior that an empty string
|
||||
// means port 0. See Issue 13610.
|
||||
return 0, nil
|
||||
}
|
||||
port, _, ok := dtoi(service, 0)
|
||||
if !ok && port != big && port != -big {
|
||||
port, err = lookupPort(network, service)
|
||||
|
|
|
|||
|
|
@ -591,6 +591,12 @@ var lookupPortTests = []struct {
|
|||
{"tcp", "65536", 0, false},
|
||||
{"udp", "-1", 0, false},
|
||||
{"udp", "65536", 0, false},
|
||||
|
||||
// Issue 13610: LookupPort("tcp", "")
|
||||
{"tcp", "", 0, true},
|
||||
{"tcp6", "", 0, true},
|
||||
{"tcp4", "", 0, true},
|
||||
{"udp", "", 0, true},
|
||||
}
|
||||
|
||||
func TestLookupPort(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue