Commit c20ced95 authored by Mikio Hara's avatar Mikio Hara Committed by Russ Cox

net: return correct local address for an accepted TCP connection

Fixes #2127.

R=rsc
CC=golang-dev
https://golang.org/cl/4873043
parent a2677cf3
...@@ -591,13 +591,13 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err os. ...@@ -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. // because we have put fd.sysfd into non-blocking mode.
syscall.ForkLock.RLock() syscall.ForkLock.RLock()
var s, e int var s, e int
var sa syscall.Sockaddr var rsa syscall.Sockaddr
for { for {
if fd.closing { if fd.closing {
syscall.ForkLock.RUnlock() syscall.ForkLock.RUnlock()
return nil, os.EINVAL return nil, os.EINVAL
} }
s, sa, e = syscall.Accept(fd.sysfd) s, rsa, e = syscall.Accept(fd.sysfd)
if e != syscall.EAGAIN { if e != syscall.EAGAIN {
break break
} }
...@@ -616,7 +616,8 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err os. ...@@ -616,7 +616,8 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err os.
syscall.Close(s) syscall.Close(s)
return nil, err return nil, err
} }
nfd.setAddr(fd.laddr, toAddr(sa)) lsa, _ := syscall.Getsockname(nfd.sysfd)
nfd.setAddr(toAddr(lsa), toAddr(rsa))
return nfd, nil return nfd, nil
} }
......
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