Page 1 of 2

[TCP] My OS acked the packet but windows is still sending

Posted: Sat Jan 14, 2023 2:52 pm
by nifanfa
Image
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;

Re: [TCP] My OS acked the packet but windows is still sendin

Posted: Sat Jan 14, 2023 3:02 pm
by nifanfa
Image
I think the seq and ack is in the right value. but why windows is still resending the packet?

Re: [TCP] My OS acked the packet but windows is still sendin

Posted: Sat Jan 14, 2023 3:16 pm
by nifanfa
Image

Re: [TCP] My OS acked the packet but windows is still sendin

Posted: Sat Jan 14, 2023 3:38 pm
by nifanfa
This is the whole process:
Image

Re: [TCP] My OS acked the packet but windows is still sendin

Posted: Sat Jan 14, 2023 3:43 pm
by Klakap
well I am not sure what is this connection supposed to do, but it seems like you are not responding to request in PSH ACK packet, you just ancknowledge it with length 0, so windows is trying to get some answer from you.

Re: [TCP] My OS acked the packet but windows is still sendin

Posted: Sat Jan 14, 2023 3:46 pm
by nifanfa
Klakap wrote:well I am not sure what is this connection supposed to do, but it seems like you are not responding to request in PSH ACK packet, you just ancknowledge it with length 0, so windows is trying to get some answer from you.
So all i have to do is send the same packet to windows with PSH ACK flags?

Re: [TCP] My OS acked the packet but windows is still sendin

Posted: Sat Jan 14, 2023 3:48 pm
by Klakap
no, just to clarify subject, what IP address are you in this connection?

Re: [TCP] My OS acked the packet but windows is still sendin

Posted: Sat Jan 14, 2023 3:51 pm
by nifanfa
Klakap wrote:no, just to clarify subject, what IP address are you in this connection?
The IP address is the IP address of the vmware virtual NIC, I'm using host-only mode, I set up a tcp server on windows so my OS can connect to it

Re: [TCP] My OS acked the packet but windows is still sendin

Posted: Sat Jan 14, 2023 3:53 pm
by Klakap
so you are 192.168.81.20?

Re: [TCP] My OS acked the packet but windows is still sendin

Posted: Sat Jan 14, 2023 3:55 pm
by nifanfa
Klakap wrote:so you are 192.168.81.20?
Yes. But I just picked one randomly because all you have to do is answer the windows saying the ip is yours and tell your mac address using arp procotol

Re: [TCP] My OS acked the packet but windows is still sendin

Posted: Sat Jan 14, 2023 3:56 pm
by nifanfa
Klakap wrote:so you are 192.168.81.20?
as you can see from the wireshark screenshot. it just worked but windows just resending the same packet

Re: [TCP] My OS acked the packet but windows is still sendin

Posted: Sat Jan 14, 2023 3:59 pm
by Klakap
okay, so you successfully estabilished connection, but after that, windows send you PSH ACK packet with data length 3. what is in this packet?

Re: [TCP] My OS acked the packet but windows is still sendin

Posted: Sat Jan 14, 2023 4:00 pm
by nifanfa
Klakap wrote:well I am not sure what is this connection supposed to do, but it seems like you are not responding to request in PSH ACK packet, you just ancknowledge it with length 0, so windows is trying to get some answer from you.
Image
I just tried to use TCP to communicate between 2 windows PCs and i think the way i respose is right...
it also just replied it with length 0 ancknowledge

Re: [TCP] My OS acked the packet but windows is still sendin

Posted: Sat Jan 14, 2023 4:01 pm
by nifanfa
Klakap wrote:okay, so you successfully estabilished connection, but after that, windows send you PSH ACK packet with data length 3. what is in this packet?
just random text to make sure my OS can receive the text

Re: [TCP] My OS acked the packet but windows is still sendin

Posted: Sat Jan 14, 2023 4:06 pm
by Klakap
I see that you use same source and destination port. I am not TCP expert, but it seems wrong to me. I think you should use different port for you and different port for server.