networking · beginner · ~15 min
Tokenise an IPv6 address by ':'.
Count the colon-separated groups (hextets) in a fully written IPv6 address.
Implement int count_groups(const char *addr). The address is in full form (no :: compression), so the answer is simply the number of colons plus 1.
addr: an IPv6 address string in full (uncompressed) form.The count of :-separated groups.
count_groups("2001:db8:0:0:0:0:0:1") -> 8
count_groups("a:b:c") -> 3
addr: an IPv6 address string in full (uncompressed) form.
The number of ':'-separated groups (colons + 1).
Assume full form with no '::' compression.
int count_groups(const char *addr) {
/* TODO */
return 0;
}
Assuming read/write transmits all requested bytes at once; ignoring socket file descriptor cleanup; unhandled endianness conversions.
Short reads/writes; peer closing socket (recv returns 0); signal interruption (EINTR); non-blocking EAGAIN.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.