如何检测和删除以太网填充
How to detect and remove ethernet padding
我正在为我的 os 编写网络堆栈。
从以太网接收数据时,如果数据小于 64 字节,我必须检测并删除填充,并设置数据长度,如标准所述。
这样做的算法是什么?
如果数据中包含'a0',则小于64字节,将被补齐。如果我按字节检查,我会得到第二个bye 0,所以它也会被算作填充数据,但事实并非如此。
Type/Length 字段会告诉您负载有多大。 Wireshark 有一个很好的 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).
我正在为我的 os 编写网络堆栈。 从以太网接收数据时,如果数据小于 64 字节,我必须检测并删除填充,并设置数据长度,如标准所述。
这样做的算法是什么?
如果数据中包含'a0',则小于64字节,将被补齐。如果我按字节检查,我会得到第二个bye 0,所以它也会被算作填充数据,但事实并非如此。
Type/Length 字段会告诉您负载有多大。 Wireshark 有一个很好的 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).