cybersecurity · intermediate · ~15 min · safe pentest lab
Practise defensive parsing of a real protocol from sample text.
Given the struct
typedef struct { char method[8]; char path[256]; char version[16]; } http_req_t;
implement int parse_request_line(const char *line, http_req_t *out) that parses METHOD PATH VERSION\r\n into the struct. Return 0 on success, -1 on malformed input.
#include <stdio.h>
#include <string.h>
int parse_request_line(const char *line, http_req_t *out) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.