Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Locate the payload in an Ethernet frame

Hardware interview practice

Locate the payload in an Ethernet frame

EasyFirmware & ValidationC

Firmware receives a complete Ethernet frame without FCS. It supports either an untagged header or one 802.1Q tag with TPID 0x8100. Write a bounded C parser that returns EtherType and payload offset.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Starting point

Question code

int eth_payload(const uint8_t *f, size_t n,
uint16_t *type, size_t *offset);
Reviewed example

Work through one case

Input
An untagged frame of at least 14 bytes has f[12]=8'h08 and f[13]=8'h00.
Expected output
Return 0 with type=16'h0800 and offset=14.

The big-endian field is not the VLAN TPID 16'h8100, so it is the EtherType and the payload begins after the base Ethernet header.

What to cover

Requirements

  1. Require f, type, and offset and require n>=14; return -1 and preserve outputs otherwise.
  2. Read the big-endian field at bytes 12 and 13. If it is not 0x8100, return it as type and set offset=14.
  3. If it is 0x8100, require n>=18, read big-endian inner EtherType at bytes 16 and 17, and set offset=18.
  4. On success write both outputs and return 0; support exactly zero or one VLAN tag.
Continue practicing

Related questions

Firmware & ValidationBounded byte-string palindrome check→Firmware & ValidationBounded MMIO command driver→Firmware & ValidationCount errors in a build report→
asic.fyi · Learn silicon end to end.info@asic.fyi