need TCP acknowledgment number
This commit is contained in:
parent
255366c337
commit
fe2b52f168
|
@ -66,6 +66,7 @@ type
|
||||||
tcpPortSrc*: Port
|
tcpPortSrc*: Port
|
||||||
tcpPortDst*: Port
|
tcpPortDst*: Port
|
||||||
tcpSeqNumber*: uint32
|
tcpSeqNumber*: uint32
|
||||||
|
tcpAckNumber*: uint32
|
||||||
tcpFlags*: set[TcpFlag]
|
tcpFlags*: set[TcpFlag]
|
||||||
else:
|
else:
|
||||||
discard
|
discard
|
||||||
|
@ -94,6 +95,7 @@ proc parseEthernetPacket*(input: string): IpPacket =
|
||||||
tcpPortSrc: Port(ntohs(tcpHeader.th_sport)),
|
tcpPortSrc: Port(ntohs(tcpHeader.th_sport)),
|
||||||
tcpPortDst: Port(ntohs(tcpHeader.th_dport)),
|
tcpPortDst: Port(ntohs(tcpHeader.th_dport)),
|
||||||
tcpSeqNumber: ntohl(tcpHeader.th_seq),
|
tcpSeqNumber: ntohl(tcpHeader.th_seq),
|
||||||
|
tcpAckNumber: ntohl(tcpHeader.th_ack),
|
||||||
tcpFlags: cast[set[TcpFlag]](tcpHeader.th_flags))
|
tcpFlags: cast[set[TcpFlag]](tcpHeader.th_flags))
|
||||||
else:
|
else:
|
||||||
result = IpPacket(protocol: other)
|
result = IpPacket(protocol: other)
|
||||||
|
@ -153,7 +155,7 @@ proc serialize*(packet: IpPacket): string =
|
||||||
tcpHeader.th_sport = htons(packet.tcpPortSrc.uint16)
|
tcpHeader.th_sport = htons(packet.tcpPortSrc.uint16)
|
||||||
tcpHeader.th_dport = htons(packet.tcpPortDst.uint16)
|
tcpHeader.th_dport = htons(packet.tcpPortDst.uint16)
|
||||||
tcpHeader.th_seq = htonl(packet.tcpSeqNumber)
|
tcpHeader.th_seq = htonl(packet.tcpSeqNumber)
|
||||||
tcpHeader.th_ack = 0
|
tcpHeader.th_ack = htonl(packet.tcpAckNumber)
|
||||||
tcpHeader.th_off = 5
|
tcpHeader.th_off = 5
|
||||||
tcpHeader.th_flags = cast[uint8](packet.tcpFlags)
|
tcpHeader.th_flags = cast[uint8](packet.tcpFlags)
|
||||||
tcpHeader.th_win = htons(1452 * 10)
|
tcpHeader.th_win = htons(1452 * 10)
|
||||||
|
|
|
@ -101,6 +101,7 @@ proc captureAndResendAck(puncher: TcpSyniPuncher, captureFd: AsyncFD,
|
||||||
tcpPortSrc: puncher.srcPort,
|
tcpPortSrc: puncher.srcPort,
|
||||||
tcpPortDst: parsed.tcpPortDst,
|
tcpPortDst: parsed.tcpPortDst,
|
||||||
tcpSeqNumber: parsed.tcpSeqNumber,
|
tcpSeqNumber: parsed.tcpSeqNumber,
|
||||||
|
tcpAckNumber: parsed.tcpAckNumber,
|
||||||
tcpFlags: parsed.tcpFlags)
|
tcpFlags: parsed.tcpFlags)
|
||||||
await injectFd.injectTcpPacket(ipPacket)
|
await injectFd.injectTcpPacket(ipPacket)
|
||||||
return
|
return
|
||||||
|
@ -199,6 +200,7 @@ proc accept*(puncher: TcpSyniPuncher): Future[AsyncSocket] {.async.} =
|
||||||
tcpPortSrc: dstPort,
|
tcpPortSrc: dstPort,
|
||||||
tcpPortDst: puncher.srcPort,
|
tcpPortDst: puncher.srcPort,
|
||||||
tcpSeqNumber: seqNum,
|
tcpSeqNumber: seqNum,
|
||||||
|
tcpAckNumber: 0,
|
||||||
tcpFlags: {SYN})
|
tcpFlags: {SYN})
|
||||||
asyncCheck rawFd.injectTcpPacket(ipPacket)
|
asyncCheck rawFd.injectTcpPacket(ipPacket)
|
||||||
let sock = newAsyncSocket()
|
let sock = newAsyncSocket()
|
||||||
|
|
Loading…
Reference in New Issue