cybersecurity · intermediate · ~15 min · safe pentest lab
Read a little-endian field at a fixed offset.
Read the captured-length field from a pcap per-packet record header — the count that tells you how many bytes follow before the next record.
Implement unsigned pcap_incl_len(const unsigned char *rec) that returns incl_len, the little-endian 32-bit value at offset 8.
rec: a byte buffer (at least 16 bytes) holding one pcap record header. The header is four little-endian 32-bit fields in order: ts_sec, ts_usec, incl_len, orig_len. The grader passes a fixed buffer.Returns unsigned: the incl_len field assembled from rec[8..11], low byte first.
rec[8..11] = 0x40 0x01 0x00 0x00
pcap_incl_len(rec) -> 0x140
A byte buffer rec of at least 16 bytes (a pcap record header).
An unsigned: the LE32 incl_len field at offset 8.
incl_len is the LE32 at offset 8. Assemble from bytes; no pointer casts.
unsigned pcap_incl_len(const unsigned char *rec) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.