Reputation: 3585
I need to handle Ethernet frame directly in C. And I got confused by the order of fields in Ethernet frame header. This is a programming question, so please do not mark it as offtopic.
The following figure is from Page 85 of book "TCP/IP Illustrated Volume 1, 2nd Edition".
As it shows, the "length or type" field precedes the "P/Q Tag" field (if there is any).
However, after hexdumping the frame I received, I realized the frame I received has "length or type" follows "P/Q Tag". See below
0100 5e00 007b Destination MAC (multicast)
000f 5325 fb00 Source MAC
8100 Q-tagged frame. (802.1q standard uses it to denote VLAN).
0065 Prio (3 bits), CFI (1bit), VLAN ID(12 bit)
0800 EtherType (Type field)
4500 IP packet starts from here.
Question 1: What is the order of these two fields.
Question 2: How can I check the size of Ethernet frame header correctly. Need to know where the IP packet starts.
Upvotes: 2
Views: 2491
Reputation: 3585
It is an error in the textbook (only in the 2nd edition, see EJP's comment). Not only my code shows the Q-Tag is before the "Length/Type" field. Also see the following open source code from OpenOnload.
openonload-201405-u1/src/include/ci/net/ethernet.h
typedef struct ci_ether_hdr_s {
ci_uint8 ether_dhost[ETH_ALEN];
ci_uint8 ether_shost[ETH_ALEN];
ci_uint16 ether_type;
} ci_ether_hdr;
typedef struct {
ci_uint8 ether_dhost[ETH_ALEN]; /* destination eth addr */
ci_uint8 ether_shost[ETH_ALEN]; /* source ether addr */
ci_uint16 ether_vtype; /* vlan type field 0x8100 */
ci_uint16 ether_vtag; /* vlan tag */
ci_uint16 ether_type; /* packet type ID field */
} ci_ethhdr_vlan_t;
Upvotes: 2