tcpudpraw-ethernet

Ethernet frame transport layer recognition


Recently I've been working on raw ethernet support in embedded system. Mostly for educational purposes and know-how. Using some data found on google i was able to implement ARP support, and separate UDP/TCP transport layer support. Unfortunately, I have a problem with supporting them both (UDP/TCP) at the same time. Basically i cannot recognize incoming frame protocol, therefore cannot decide if send it to UDP or TCP handler. Cannot send it to both without risk of getting malformed data. I expected some bitfield denoting that information, but cannot find it.

I am looking for this information for several days but cannot find any source, propably because i am missunderstanding something.

Can i ask some more experienced IT for help by explaining subject/hinting where to look? I feel like i am in dead end.

Thank You in advance.


Solution

  • TCP/UDP shouldn't be directly embedded into an Ethernet frame. A TCP segment should be inside an IP packet with Type = 6, and the IP packet should be inside the Ethernet Frame with EtherType= 0x800 (for IPv4):

         Ethernet EtherType=0x800 (IPv4)
       +----------------------------------+
       |          IP Type=6 (TCP)         |
       |     +-------------------------+  |
       |     |                         |  |
       |     |     +---------------+   |  |
       |     |     |   TCP         |   |  |
       |     |     |               |   |  |
       |     |     +---------------+   |  |
       |     |                         |  |
       |     +-------------------------+  |
       |                                  |
       +----------------------------------+
    

    For UDP, it's the same, only the IP type is 17 instead of 6.