I am sending/receiving Ethernet frames using RAW sockets in an embedded environment (sendto/recvfrom). I am pushing the contents of a file on one end of the socket and receiving it on the other end (Across 2 devices over point-to-point Ethernet link). The maximum Ethernet frame is 1500 bytes but it can be less also. I noticed that the complete file gets transferred but some chunks of the file are not in the correct order.
I then used a sequence number as the first byte in my Ethernet payload and noticed that on the receiving side I am getting out-of-order Ethernet frames. I thought recvfrom would always pick the first frame in the queue. I checked all the options of the socket and I couldn't find any options which would force the kernel to deliver the frames in order. Below is my assumption,
1. Sending side sent 2 frames a large frame A (Eg: 1500 bytes) and a small frame B (Eg: 500 bytes).
2. On the receiving side, the kernel received the smaller frame B before frame A was completely received. Hence I am seeing out-of-order reception.
How can I ensure my recvfrom gets frames in the order sent ?