cybersecurity · intermediate · ~15 min · safe pentest lab
Practise extracting structured fields from a text report.
Extract the open ports from a saved Nmap report — pulling structured fields out of a text report.
Implement size_t open_ports(const char *report, int *out, size_t out_cap) that stores each open port number into out (up to out_cap of them) and returns how many it stored.
report: a NUL-terminated multi-line string in Nmap -oN format, baked into the harness. A line marks an open port when it looks like <port>/tcp<spaces>open<spaces>....out, out_cap: the output array and its capacity.Returns size_t: the number of port numbers stored (the function never stores more than out_cap).
report with 22/tcp open, 80/tcp open, 443/tcp closed, 8080/tcp open
open_ports(report, out, 10) -> 3, out = {22, 80, 8080}
out_cap is reached./tcp, whitespace, and open. Static fixture only — the exercise never runs Nmap.A NUL-terminated Nmap -oN report, an output int array, and its capacity.
A size_t: the number of open port numbers stored in out (up to out_cap).
Match lines like
#include <stdio.h>
#include <string.h>
#include <stddef.h>
size_t open_ports(const char *report, int *out, size_t out_cap) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.