From ef68519eecaae39b24f6c7a02b145b313f707e88 Mon Sep 17 00:00:00 2001 From: Christian Ulrich Date: Sat, 18 Jul 2020 13:06:22 +0200 Subject: [PATCH] fix 'invalid argument' by using a separate socket for listening --- tcp_syni.nim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tcp_syni.nim b/tcp_syni.nim index 707dad0..de9c676 100644 --- a/tcp_syni.nim +++ b/tcp_syni.nim @@ -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: