fix 'invalid argument' by using a separate socket for listening

This commit is contained in:
Christian Ulrich 2020-07-18 13:06:22 +02:00
parent 974f324aec
commit ef68519eec
No known key found for this signature in database
GPG Key ID: 8241BE099775A097
1 changed files with 7 additions and 2 deletions

View File

@ -133,8 +133,8 @@ proc doConnect(srcIp: IpAddress, srcPort: Port, dstIp: IpAddress,
proc doAccept(srcIp: IpAddress, srcPort: Port, dstIp: IpAddress, dstPort: Port,
seqNums: seq[uint32], future: Future[AsyncSocket]) {.async.} =
let sock = newAsyncSocket()
try:
let sock = newAsyncSocket()
sock.setSockOpt(OptReuseAddr, true)
sock.getFd.setSockOptInt(IPPROTO_IP, IP_TTL, 2)
sock.bindAddr(srcPort, $srcIp)
@ -144,9 +144,14 @@ proc doAccept(srcIp: IpAddress, srcPort: Port, dstIp: IpAddress, dstPort: Port,
except OSError:
discard
try:
# FIXME: timeout
let rawFd = setupTcpInjectingSocket()
asyncCheck injectSyns(rawFd, dstIp, dstPort, srcIp, srcPort, seqNums)
sock.getFd.setSockOptInt(IPPROTO_IP, IP_TTL, 64)
let sock = newAsyncSocket()
sock.setSockOpt(OptReuseAddr, true)
sock.setSockOpt(OptReusePort, true)
sock.bindAddr(srcPort, $srcIp)
sock.listen()
let connectedSock = await sock.accept()
future.complete(connectedSock)
except OSError as e: