From: Mikio Hara Date: Tue, 29 Apr 2014 03:37:16 +0000 (+0900) Subject: net: make WriteTo, WriteToIP and WriteMsgIP fail when IPConn is already connected X-Git-Tag: go1.3beta2~169 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7e41abbc6b9f00f84374c69f3acb63b56fcf4728;p=gostls13.git net: make WriteTo, WriteToIP and WriteMsgIP fail when IPConn is already connected This CL tries to fill the gap between Linux and other Unix-like systems in the same way UDPConn and UnixConn already did. Fixes #7887. LGTM=iant R=iant CC=golang-codereviews https://golang.org/cl/97810043 --- diff --git a/src/pkg/net/iprawsock_posix.go b/src/pkg/net/iprawsock_posix.go index 26fc06e1b6..bbb3f3ed66 100644 --- a/src/pkg/net/iprawsock_posix.go +++ b/src/pkg/net/iprawsock_posix.go @@ -133,6 +133,9 @@ func (c *IPConn) WriteToIP(b []byte, addr *IPAddr) (int, error) { if !c.ok() { return 0, syscall.EINVAL } + if c.fd.isConnected { + return 0, &OpError{Op: "write", Net: c.fd.net, Addr: addr, Err: ErrWriteToConnected} + } if addr == nil { return 0, &OpError{Op: "write", Net: c.fd.net, Addr: nil, Err: errMissingAddress} } @@ -162,6 +165,9 @@ func (c *IPConn) WriteMsgIP(b, oob []byte, addr *IPAddr) (n, oobn int, err error if !c.ok() { return 0, 0, syscall.EINVAL } + if c.fd.isConnected { + return 0, 0, &OpError{Op: "write", Net: c.fd.net, Addr: addr, Err: ErrWriteToConnected} + } if addr == nil { return 0, 0, &OpError{Op: "write", Net: c.fd.net, Addr: nil, Err: errMissingAddress} }