EthCodec – a layer 2 codec
EthCodec is a data link layer codec and is one of the top-level codecs. A top-level codec is one of the codecs that starts the packet decoding functionality; the data link layer (in this case, the Ethernet layer) is the outermost header that needs to be decoded first before other layers can be decoded.
There are not many validations done at this layer. The codec checks whether the total length of the packet data handed over is less than the Ethernet
header length, which is 14 bytes. If this is indeed the case, a codec event is generated, namely, a truncated Ethernet header.
In normal cases, the Ethernet
header will not be truncated (the packet data length will be more than 14 bytes). After this validation is checked, the codec lays the Ethernet
header structure over the packet data and checks the type
field. The Ethernet
header structure is defined in the src/protocols/eth.h
header file and is as follows:
struct EtherHdr { ...