need TCP acknowledgment number

This commit is contained in:
Christian Ulrich 2020-08-23 22:38:10 +02:00
parent 255366c337
commit fe2b52f168
No known key found for this signature in database
GPG Key ID: 8241BE099775A097
2 changed files with 5 additions and 1 deletions

View File

@ -66,6 +66,7 @@ type
tcpPortSrc*: Port
tcpPortDst*: Port
tcpSeqNumber*: uint32
tcpAckNumber*: uint32
tcpFlags*: set[TcpFlag]
else:
discard
@ -94,6 +95,7 @@ proc parseEthernetPacket*(input: string): IpPacket =
tcpPortSrc: Port(ntohs(tcpHeader.th_sport)),
tcpPortDst: Port(ntohs(tcpHeader.th_dport)),
tcpSeqNumber: ntohl(tcpHeader.th_seq),
tcpAckNumber: ntohl(tcpHeader.th_ack),
tcpFlags: cast[set[TcpFlag]](tcpHeader.th_flags))
else:
result = IpPacket(protocol: other)
@ -153,7 +155,7 @@ proc serialize*(packet: IpPacket): string =
tcpHeader.th_sport = htons(packet.tcpPortSrc.uint16)
tcpHeader.th_dport = htons(packet.tcpPortDst.uint16)
tcpHeader.th_seq = htonl(packet.tcpSeqNumber)
tcpHeader.th_ack = 0
tcpHeader.th_ack = htonl(packet.tcpAckNumber)
tcpHeader.th_off = 5
tcpHeader.th_flags = cast[uint8](packet.tcpFlags)
tcpHeader.th_win = htons(1452 * 10)

View File

@ -101,6 +101,7 @@ proc captureAndResendAck(puncher: TcpSyniPuncher, captureFd: AsyncFD,
tcpPortSrc: puncher.srcPort,
tcpPortDst: parsed.tcpPortDst,
tcpSeqNumber: parsed.tcpSeqNumber,
tcpAckNumber: parsed.tcpAckNumber,
tcpFlags: parsed.tcpFlags)
await injectFd.injectTcpPacket(ipPacket)
return
@ -199,6 +200,7 @@ proc accept*(puncher: TcpSyniPuncher): Future[AsyncSocket] {.async.} =
tcpPortSrc: dstPort,
tcpPortDst: puncher.srcPort,
tcpSeqNumber: seqNum,
tcpAckNumber: 0,
tcpFlags: {SYN})
asyncCheck rawFd.injectTcpPacket(ipPacket)
let sock = newAsyncSocket()