Should Ethernet Header Length 14?

Code snippet from here :

void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data) { .... /* retireve the position of the ip header */ ih = (ip_header *) (pkt_data + 14); //length of ethernet header .... 

But this image does not necessarily say 14 :

alt text
(source: Lewis at www.dcs.gla.ac.uk )

How should I do it right?

+5
source share
4 answers

In 802.3, both the source and destination addresses are 48-bit MAC addresses. 6 + 6 + 2 = 14

+6
source

Yes, that's 14 in most cases for a terminal station scenario. Unless you have an 802.1Q frame, this will throw you another 4 bytes. 802.1Q is mainly used for VLAN and QoS tags when transmitting a router / router.

The separator of the preamble and the start frame is mainly used by low level firmware to capture the frame. By the time we (the application) have access to the ethernet frame, in the general case we do not have a preamble or a separator of the initial frame.

From what I can recall, a 2-byte byte length was part of Ethernet I, which never received recognition. And Ethernet II / 802.3, which has 6 byte addresses, is the real shared Ethernet we are currently using.

I also want to mention that the indentation is 0-46, where 46 came from the minimum limit of 64 bytes per ethernet frame for collision detection (CD) purposes. 46 (pad) + 14 (dmac, smac, type) + 4 (CRC) = 64 bytes

+3
source

The ethernet header has a fixed width, but extension protocols such as 802.1q for vlan / qos are common and effectively extend the L2 header.

+1
source

Wikipedia has a nice picture frame

Wiki

IPv4 / v6 are layer 3 protocols.

0
source

Source: https://habr.com/ru/post/1309239/


All Articles