Thread: Reception of out-of-order Ethernet frames on RAW socket

  1. #1
    Registered User
    Join Date
    May 2016
    Posts
    2

    Reception of out-of-order Ethernet frames on RAW socket

    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 ?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    The short answer is you can't.
    Transport layer - Wikipedia, the free encyclopedia

    If you want a reliable ordered connection, you need to use something like TCP. Internally, TCP uses sequence numbers to sort things out for you.

    If you're using UDP, or some DIY protocol, you're on your own.

    What is likely happening in your case, is the first attempt at the 1500 packet failed, and was retried - but only after the 500 byte packet had been successfully transmitted.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2016
    Posts
    2
    I am transmitting data at L2, so there is no question of TCP/UDP. I used tcpdump to capture the frames at both ends and got to know that the frames arrive in order. But I think the kernel is sending the smaller frame before sending the larger frame. I am not sure how to disable this in the kernel.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    There are a huge number of knobs to twiddle with.
    https://www.kernel.org/doc/Documenta.../ip-sysctl.txt
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Libnet performance sending RAW ethernet frames
    By Krulle in forum C Programming
    Replies: 5
    Last Post: 05-06-2012, 12:44 PM
  2. Sdi? Mdi? Frames?
    By execute in forum Windows Programming
    Replies: 4
    Last Post: 05-16-2006, 08:05 PM
  3. Video Frames
    By Speedy5 in forum C# Programming
    Replies: 2
    Last Post: 01-04-2004, 06:35 PM
  4. HTML frames
    By Monster in forum Tech Board
    Replies: 3
    Last Post: 08-23-2002, 02:02 AM
  5. Getting the FPS (Frames Per Second)
    By Unregistered in forum Game Programming
    Replies: 12
    Last Post: 05-05-2002, 10:58 AM

Tags for this Thread