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

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
nifanfa
Member
Member
Posts: 104
Joined: Tue Aug 17, 2021 10:40 am
Libera.chat IRC: visitor
Location: CN
Contact:

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

Post 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;
nifanfa
Member
Member
Posts: 104
Joined: Tue Aug 17, 2021 10:40 am
Libera.chat IRC: visitor
Location: CN
Contact:

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

Post by nifanfa »

Image
I think the seq and ack is in the right value. but why windows is still resending the packet?
nifanfa
Member
Member
Posts: 104
Joined: Tue Aug 17, 2021 10:40 am
Libera.chat IRC: visitor
Location: CN
Contact:

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

Post by nifanfa »

Image
nifanfa
Member
Member
Posts: 104
Joined: Tue Aug 17, 2021 10:40 am
Libera.chat IRC: visitor
Location: CN
Contact:

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

Post by nifanfa »

This is the whole process:
Image
Klakap
Member
Member
Posts: 297
Joined: Sat Mar 10, 2018 10:16 am

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

Post 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.
nifanfa
Member
Member
Posts: 104
Joined: Tue Aug 17, 2021 10:40 am
Libera.chat IRC: visitor
Location: CN
Contact:

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

Post 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?
Klakap
Member
Member
Posts: 297
Joined: Sat Mar 10, 2018 10:16 am

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

Post by Klakap »

no, just to clarify subject, what IP address are you in this connection?
nifanfa
Member
Member
Posts: 104
Joined: Tue Aug 17, 2021 10:40 am
Libera.chat IRC: visitor
Location: CN
Contact:

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

Post 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
Klakap
Member
Member
Posts: 297
Joined: Sat Mar 10, 2018 10:16 am

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

Post by Klakap »

so you are 192.168.81.20?
nifanfa
Member
Member
Posts: 104
Joined: Tue Aug 17, 2021 10:40 am
Libera.chat IRC: visitor
Location: CN
Contact:

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

Post 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
nifanfa
Member
Member
Posts: 104
Joined: Tue Aug 17, 2021 10:40 am
Libera.chat IRC: visitor
Location: CN
Contact:

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

Post 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
Klakap
Member
Member
Posts: 297
Joined: Sat Mar 10, 2018 10:16 am

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

Post 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?
nifanfa
Member
Member
Posts: 104
Joined: Tue Aug 17, 2021 10:40 am
Libera.chat IRC: visitor
Location: CN
Contact:

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

Post 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
nifanfa
Member
Member
Posts: 104
Joined: Tue Aug 17, 2021 10:40 am
Libera.chat IRC: visitor
Location: CN
Contact:

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

Post 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
Klakap
Member
Member
Posts: 297
Joined: Sat Mar 10, 2018 10:16 am

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

Post 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.
Post Reply