[TCP] My OS acked the packet but windows is still sending
Posted: Sat Jan 14, 2023 2:52 pm
What should tell Windows not to send more?
Here is my code to handle "Established"
Code: Select all
case TCPStatus.Established:
{
if (tcp_hdr->Flags.HasFlag(TCPFlags.TCP_ACK))
{
if(client.SndUna < tcp_hdr->Ack && tcp_hdr->Ack <= client.SndNxt)
{
client.SndUna = tcp_hdr->Ack;
if(client.SndWl1<tcp_hdr->Seq || (client.SndWl1 == tcp_hdr->Seq && client.SndWl2 <= tcp_hdr->Ack))
{
client.SndWnd = tcp_hdr->WindowSize;
client.SndWl1 = tcp_hdr->Seq;
client.SndWl2 = tcp_hdr->Ack;
}
}
if(tcp_hdr->Ack < client.SndUna)
{
return;
}
if(tcp_hdr->Ack > client.SndNxt)
{
TCPSend(client, client.SndNxt, TCPFlags.TCP_ACK, null, 0);
}
if (tcp_hdr->Flags.HasFlag(TCPFlags.TCP_PSH))
{
client.OnData(buffer, length);
client.RcvNxt += (uint)length;
TCPSend(client, client.SndNxt, TCPFlags.TCP_ACK, null, 0);
}else if (tcp_hdr->Flags.HasFlag(TCPFlags.TCP_FIN))
{
client.RcvNxt++;
TCPSend(client, client.SndNxt, TCPFlags.TCP_ACK, null, 0);
client.Status = TCPStatus.TimeWait;
client.Status = TCPStatus.Closed;
}
if(length > 0 && tcp_hdr->Seq >= client.RcvNxt)
{
client.OnData(buffer, length);
client.RcvNxt += (uint)length;
}
}
if (tcp_hdr->Flags.HasFlag(TCPFlags.TCP_RST))
{
client.Status = TCPStatus.Closed;
}else if (tcp_hdr->Flags.HasFlag(TCPFlags.TCP_FIN))
{
client.RcvNxt++;
TCPSend(client, client.SndNxt, TCPFlags.TCP_ACK, null, 0);
client.Status = TCPStatus.CloseWait;
TCPSend(client, client.SndNxt, TCPFlags.TCP_FIN, null, 0);
client.Status = TCPStatus.LastAcknowledge;
}
}
break;