diff --git a/tcp_syni.nim b/tcp_syni.nim index 803ceb2..904c815 100644 --- a/tcp_syni.nim +++ b/tcp_syni.nim @@ -1,6 +1,6 @@ import asyncdispatch, asyncnet, strformat -from net import IpAddress, Port, `$`, `==`, getPrimaryIPAddr -from nativesockets import setSockOptInt +from net import IpAddress, Port, `$`, `==`, getPrimaryIPAddr, toSockAddr +from nativesockets import SockAddr, Sockaddr_storage, SockLen, setSockOptInt import asyncutils import ip_packet import network_interface @@ -90,7 +90,17 @@ proc injectSyns(rawFd: AsyncFD, srcIp: IpAddress, srcPort: Port, tcpPortDst: srcPort, tcpSeqNumber: seqNum, tcpFlags: {SYN}) - asyncCheck rawFd.send(serialize(ipPacket)) + echo &"injecting {srcIP}:{srcPort.int} -> {dstIp}:{dstPort.int} (seq {seqNum})" + try: + let packet = serialize(ipPacket) + var sockaddr: Sockaddr_storage + var sockaddrLen: SockLen + toSockAddr(dstIp, dstPort, sockaddr, sockaddrLen) + await rawFd.sendTo(packet.cstring, packet.len, + cast[ptr SockAddr](addr sockaddr), sockaddrLen) + echo &"injected {srcIP}:{srcPort.int} -> {dstIp}:{dstPort.int} (seq {seqNum})" + except OSError as e: + echo "cannot inject: ", e.msg proc initPuncher*(srcPort: Port, dstIp: IpAddress, dstPorts: array[3, Port], seqNums: seq[uint32] = @[]): Future[TcpSyniPuncher] {.async.} =