fix 'invalid argument' by using a separate socket for listening
This commit is contained in:
parent
974f324aec
commit
ef68519eec
|
@ -133,8 +133,8 @@ proc doConnect(srcIp: IpAddress, srcPort: Port, dstIp: IpAddress,
|
||||||
|
|
||||||
proc doAccept(srcIp: IpAddress, srcPort: Port, dstIp: IpAddress, dstPort: Port,
|
proc doAccept(srcIp: IpAddress, srcPort: Port, dstIp: IpAddress, dstPort: Port,
|
||||||
seqNums: seq[uint32], future: Future[AsyncSocket]) {.async.} =
|
seqNums: seq[uint32], future: Future[AsyncSocket]) {.async.} =
|
||||||
let sock = newAsyncSocket()
|
|
||||||
try:
|
try:
|
||||||
|
let sock = newAsyncSocket()
|
||||||
sock.setSockOpt(OptReuseAddr, true)
|
sock.setSockOpt(OptReuseAddr, true)
|
||||||
sock.getFd.setSockOptInt(IPPROTO_IP, IP_TTL, 2)
|
sock.getFd.setSockOptInt(IPPROTO_IP, IP_TTL, 2)
|
||||||
sock.bindAddr(srcPort, $srcIp)
|
sock.bindAddr(srcPort, $srcIp)
|
||||||
|
@ -144,9 +144,14 @@ proc doAccept(srcIp: IpAddress, srcPort: Port, dstIp: IpAddress, dstPort: Port,
|
||||||
except OSError:
|
except OSError:
|
||||||
discard
|
discard
|
||||||
try:
|
try:
|
||||||
|
# FIXME: timeout
|
||||||
let rawFd = setupTcpInjectingSocket()
|
let rawFd = setupTcpInjectingSocket()
|
||||||
asyncCheck injectSyns(rawFd, dstIp, dstPort, srcIp, srcPort, seqNums)
|
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()
|
let connectedSock = await sock.accept()
|
||||||
future.complete(connectedSock)
|
future.complete(connectedSock)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
|
|
Loading…
Reference in New Issue