cybersecurity · intermediate · ~12 min · safe pentest lab
Bit-field decoding from a single header byte.
Implement:
#include <stdint.h>
int classify_frame(const uint8_t *hdr);
The Frame Control field's first byte has:
bits 7..6 : subtype
bits 5..4 : also subtype
bits 3..2 : TYPE <- this is what we extract
bits 1..0 : protocol version
So type = (hdr[0] >> 2) & 0x3. Map:
NULL hdr → -1.
Every Wi-Fi forensics tool starts by classifying the frame type before it knows the layout of the rest of the bytes.
A non-NULL pointer to at least one byte (we only read hdr[0]).
0, 1, 2 (valid types) or -1 (reserved / NULL).
Two operations (shift + mask). No loops.
#include <stdint.h>
int classify_frame(const uint8_t *hdr) {
/* TODO */
(void)hdr;
return -1;
}
Reading the wrong bit position. Forgetting the NULL check. Allowing the reserved type 3 through.
All-zeros byte (type 0). Top bits set (subtype) should not affect classification.
O(1).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.