networking · beginner · ~10 min · safe pentest lab
Read a fixed-offset big-endian field with bounds checks.
#include <stdint.h>
#include <stddef.h>
int arp_opcode(const uint8_t *frame, size_t n);
The ARP opcode is a big-endian 16-bit value at byte offset 6. Return 1
(request) or 2 (reply); return -1 for NULL, n < 8, or any other opcode.
op = (frame[6]<<8) | frame[7].ARP request vs reply is the first thing an ARP-spoofing detector classifies. The opcode is two bytes at a fixed offset.
#include <stdint.h>
#include <stddef.h>
int arp_opcode(const uint8_t *frame, size_t n) {
/* TODO */
(void)frame; (void)n;
return -1;
}
Reading the wrong offset. Forgetting the n>=8 bound.
Unknown opcode. Short buffer. NULL.
O(1).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.