anupamD
anupamD

Reputation: 952

How to detect and remove ethernet padding

I am writing the network stack for my os. While receiving the data from ethernet, I have to detect and remove the padding if data is less than 64 bytes and set the data length, as the standard says.

What is the algorithm for doing this?

If the data contains 'a0' , it is less than 64 bytes and it will be padded. If I am checking bytewise, I will get the second bye 0, so it will also be counted as padded data, however it is not.

Upvotes: 3

Views: 4965

Answers (1)

Ron Maupin
Ron Maupin

Reputation: 6452

The Type/Length field will tell you how large the payload is. Wireshark has a pretty good explanation:

Therefore, if the type/length field has a value 1500 or lower, it's a length field, and is followed by an 802.2 header, otherwise it's a type field and is followed by the data for the upper layer protocol (XXX - slight duplicate of sentence above?). Note that when the length/type field is used as a length field the length value specified does not include the length of any padding bytes (e.g. if a raw ethernet frame was sent with a payload containing a single byte of data the length field would be set to 0x0001 and 45 padding bytes would be appended to the data field to bring the ethernet frame up to the required minimum 64-byte length).

Upvotes: 1

Related Questions