There might be something simple that I'm missing, but I just can't understand how related TCP segments are identified.
So let's say I want to send 2000 bytes using TCP with an MSS of 1500 bytes. I just do a send operation, and TCP segments each operation into two packets of 1500 bytes and 500 bytes. How does the reassembly mechanism know that these two packets are supposed to be reassembled, and not just two different packets of sizes 1500 and 500? If I'm not mistaken, all flags and sequence numbers will be exactly the same.
Does TCP actually differentiate between these two cases, or does this just depend on the receiving application saying how many bytes it wants to receive?
Edit: It seems the question is not very clear, so I'll try to clarify it more.
If I wrote an application that looks something like:
and another application that looks like:
send (1500) send (500)
and trace the TCP packets using something like Wireshark, in both cases I will see two packets from the same source to the same destination, and they would both have the same data length. The first packet will have a relative sequence number of 1, and the second packet will have a relative sequence number of 1501.
My question is: Looking at the traces of the two TCP packets, is there something that can identify which application I used? How does the receiving side know whether these two packets are related to each other and need to be reassembled?