cybersecurity · intermediate · ~15 min · safe pentest lab

Count subdomains of a domain

Filter lines by suffix.

Challenge

Group enumerated hosts by parent domain: count how many lines end with a given suffix.

Task

Implement int count_of_domain(const char *list, const char *domain) that returns how many lines end with the string domain (e.g. ".example.com").

Input

  • list: a NUL-terminated, \n-separated string of host entries baked into the harness.
  • domain: the suffix to match (NUL-terminated).

Output

Returns int: the number of lines whose final characters equal domain.

Example

list: "a.example.com\nb.other.com\nc.example.com\n"
count_of_domain(list, ".example.com")   ->   2

Edge cases

  • A line shorter than domain cannot match.

Rules

  • Static string only — no DNS or network.

Input format

A NUL-terminated \n-separated host list and a suffix string domain.

Output format

An int: the number of lines ending with domain.

Constraints

Suffix match each line against domain. Static string only.

Starter code

#include <string.h>

int count_of_domain(const char *list, const char *domain) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.