1
0
mirror of https://github.com/golang/go synced 2024-11-20 10:24:40 -07:00

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/32593
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
David du Colombier 2016-11-03 14:57:05 +01:00
parent aa8c8e770e
commit 97b49f660c

View File

@ -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) {
if isWildcard(raddr) {
raddr = toLocal(raddr, net)
}
f, dest, proto, name, err := startPlan9(ctx, net, raddr)
if err != nil {
return nil, err
@ -276,3 +279,28 @@ func (fd *netFD) acceptPlan9() (nfd *netFD, err error) {
}
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
}