Skip to content

Commit 23bb026

Browse files
committed
debugging
Change-Id: I6ce84c62c786f7c96dd8848ffec30701789502dd
1 parent 1eda2b5 commit 23bb026

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

src/net/cgo_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func cgoLookupHost(ctx context.Context, name string) (hosts []string, err error)
8080
func cgoLookupPort(ctx context.Context, network, service string) (port int, err error) {
8181
var hints _C_struct_addrinfo
8282
switch network {
83-
case "": // no hints
83+
case "ip": // no hints
8484
case "tcp", "tcp4", "tcp6":
8585
*_C_ai_socktype(&hints) = _C_SOCK_STREAM
8686
*_C_ai_protocol(&hints) = _C_IPPROTO_TCP

src/net/lookup.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,20 @@ const maxPortBufSize = len("mobility-header") + 10
8383

8484
func lookupPortMap(network, service string) (port int, error error) {
8585
switch network {
86-
case "tcp4", "tcp6":
87-
network = "tcp"
88-
case "udp4", "udp6":
89-
network = "udp"
86+
case "ip": // no hints
87+
if p, err := lookupPortMapWithNetwork("tcp", service); err == nil {
88+
return p, nil
89+
}
90+
return lookupPortMapWithNetwork("udp", service)
91+
case "tcp", "tcp4", "tcp6":
92+
return lookupPortMapWithNetwork("tcp", service)
93+
case "udp", "udp4", "udp6":
94+
return lookupPortMapWithNetwork("udp", service)
9095
}
96+
return 0, &DNSError{Err: "unknown network", Name: network + "/" + service}
97+
}
9198

99+
func lookupPortMapWithNetwork(network, service string) (port int, error error) {
92100
if m, ok := services[network]; ok {
93101
var lowerService [maxPortBufSize]byte
94102
n := copy(lowerService[:], service)
@@ -415,11 +423,13 @@ func LookupPort(network, service string) (port int, err error) {
415423
}
416424

417425
// LookupPort looks up the port for the given network and service.
426+
//
427+
// The network must be one of "tcp", "tcp4", "tcp6", "udp", "udp4", "udp6" or "ip".
418428
func (r *Resolver) LookupPort(ctx context.Context, network, service string) (port int, err error) {
419429
port, needsLookup := parsePort(service)
420430
if needsLookup {
421431
switch network {
422-
case "tcp", "tcp4", "tcp6", "udp", "udp4", "udp6":
432+
case "tcp", "tcp4", "tcp6", "udp", "udp4", "udp6", "ip":
423433
case "": // a hint wildcard for Go 1.0 undocumented behavior
424434
network = "ip"
425435
default:

src/net/lookup_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,16 @@ func TestLookupPortDifferentNetwork(t *testing.T) {
14751475
_, err := LookupPort("udp", "imaps")
14761476
var dnsErr *DNSError
14771477
if !errors.As(err, &dnsErr) || !dnsErr.IsNotFound {
1478+
// TODO remove, for debugging:
1479+
goLookupPort("tcp", "imaps")
1480+
t.Logf("services: %#v", services)
1481+
t.Fatalf("unexpected error: %v", err)
1482+
}
1483+
}
1484+
1485+
func TestLookupPortEmptyNetworkString(t *testing.T) {
1486+
_, err := LookupPort("", "imaps")
1487+
if err != nil {
14781488
t.Fatalf("unexpected error: %v", err)
14791489
}
14801490
}

src/net/lookup_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ func (r *Resolver) lookupPort(ctx context.Context, network, service string) (int
204204
var hints syscall.AddrinfoW
205205

206206
switch network {
207+
case "ip": // no hints
207208
case "tcp", "tcp4", "tcp6":
208209
hints.Socktype = syscall.SOCK_STREAM
209210
hints.Protocol = syscall.IPPROTO_TCP

src/net/port_unix.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build unix || js || wasip1
5+
//TODO uncomment
6+
////go:build unix || js || wasip1
67

78
// Read system port mappings from /etc/services
89

0 commit comments

Comments
 (0)