cybersecurity · intermediate · ~15 min · safe pentest lab
Tally a marker in tool output.
Tally the open ports in a saved nmap XML report by counting a marker substring.
Implement int count_open_ports(const char *xml) that returns the number of occurrences of the substring state="open".
xml: a NUL-terminated string holding saved nmap XML, baked into the harness.Returns int: how many times state="open" appears in xml.
xml contains two open and one closed port
count_open_ports(xml) -> 2
A NUL-terminated string xml of saved nmap output.
An int: the number of occurrences of state="open".
Count the exact substring state="open". Static buffer only.
#include <string.h>
int count_open_ports(const char *xml) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.