From c20ced956ece23a5e8f1d5b6e48ad9ba8e8c5d05 Mon Sep 17 00:00:00 2001 From: Mikio Hara Date: Tue, 16 Aug 2011 16:53:09 -0400 Subject: [PATCH] net: return correct local address for an accepted TCP connection Fixes #2127. R=rsc CC=golang-dev https://golang.org/cl/4873043 --- src/pkg/net/fd.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pkg/net/fd.go b/src/pkg/net/fd.go index cd1a21dc361..fd39d858c35 100644 --- a/src/pkg/net/fd.go +++ b/src/pkg/net/fd.go @@ -591,13 +591,13 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err os. // because we have put fd.sysfd into non-blocking mode. syscall.ForkLock.RLock() var s, e int - var sa syscall.Sockaddr + var rsa syscall.Sockaddr for { if fd.closing { syscall.ForkLock.RUnlock() return nil, os.EINVAL } - s, sa, e = syscall.Accept(fd.sysfd) + s, rsa, e = syscall.Accept(fd.sysfd) if e != syscall.EAGAIN { break } @@ -616,7 +616,8 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err os. syscall.Close(s) return nil, err } - nfd.setAddr(fd.laddr, toAddr(sa)) + lsa, _ := syscall.Getsockname(nfd.sysfd) + nfd.setAddr(toAddr(lsa), toAddr(rsa)) return nfd, nil }