Commit 97b49f66 authored by David du Colombier's avatar David du Colombier

net: fix Dial(":80") on Plan 9

CL 32101 fixed Dial(":80") on Windows and added TestDialLocal,
which was failing on Plan 9, because it wasn't implemented
on Plan 9.

This change implements Dial(":80") by connecting to 127.0.0.1
or ::1 (depending on network), so it works as documented.

Fixes #17760.

Change-Id: If0ff769299e09bebce11fc3708639c1d8c96c280
Reviewed-on: https://go-review.googlesource.com/32593Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent aa8c8e77
...@@ -193,6 +193,9 @@ func dialPlan9(ctx context.Context, net string, laddr, raddr Addr) (fd *netFD, e ...@@ -193,6 +193,9 @@ func dialPlan9(ctx context.Context, net string, laddr, raddr Addr) (fd *netFD, e
} }
func dialPlan9Blocking(ctx context.Context, net string, laddr, raddr Addr) (fd *netFD, err error) { func dialPlan9Blocking(ctx context.Context, net string, laddr, raddr Addr) (fd *netFD, err error) {
if isWildcard(raddr) {
raddr = toLocal(raddr, net)
}
f, dest, proto, name, err := startPlan9(ctx, net, raddr) f, dest, proto, name, err := startPlan9(ctx, net, raddr)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -276,3 +279,28 @@ func (fd *netFD) acceptPlan9() (nfd *netFD, err error) { ...@@ -276,3 +279,28 @@ func (fd *netFD) acceptPlan9() (nfd *netFD, err error) {
} }
return newFD(fd.net, name, listen, ctl, data, fd.laddr, raddr) return newFD(fd.net, name, listen, ctl, data, fd.laddr, raddr)
} }
func isWildcard(a Addr) bool {
var wildcard bool
switch a := a.(type) {
case *TCPAddr:
wildcard = a.isWildcard()
case *UDPAddr:
wildcard = a.isWildcard()
case *IPAddr:
wildcard = a.isWildcard()
}
return wildcard
}
func toLocal(a Addr, net string) Addr {
switch a := a.(type) {
case *TCPAddr:
a.IP = loopbackIP(net)
case *UDPAddr:
a.IP = loopbackIP(net)
case *IPAddr:
a.IP = loopbackIP(net)
}
return a
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment