From bec4c1b158d48fc35d1b65b277288aa01120343d Mon Sep 17 00:00:00 2001 From: Christian Ulrich Date: Wed, 7 Oct 2020 00:25:07 +0200 Subject: [PATCH] close on failed low-TTL connects too --- tcp_syni.nim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tcp_syni.nim b/tcp_syni.nim index 651eda6..619143b 100644 --- a/tcp_syni.nim +++ b/tcp_syni.nim @@ -227,8 +227,9 @@ proc connect*(puncher: TcpSyniPuncher, srcPort: Port, dstIp: IpAddress, proc prepareAccept(attempt: AcceptAttempt) {.async.} = for dstPort in attempt.dstPorts: + var sock: AsyncSocket try: - let sock = newAsyncSocket() + sock = newAsyncSocket() sock.setSockOpt(OptReuseAddr, true) sock.getFd.setSockOptInt(IPPROTO_IP, IP_TTL, 2) sock.bindAddr(attempt.srcPort, $(attempt.srcIp)) @@ -236,9 +237,9 @@ proc prepareAccept(attempt: AcceptAttempt) {.async.} = await connectFuture or sleepAsync(Timeout) if connectFuture.finished(): echo "connected during accept phase" - sock.close() except OSError: discard + sock.close() proc doAccept(puncher: TcpSyniPuncher, srcIp: IpAddress, srcPort: Port) {.async.} =