networking · beginner · ~15 min

IPv6 loopback?

Recognise the IPv6 loopback address.

Challenge

Recognise the IPv6 loopback address — the v6 equivalent of 127.0.0.1.

Task

Implement int is_ipv6_loopback(const char *addr).

Input

  • addr: a NUL-terminated IPv6 address string.

Output

Return 1 if addr is exactly "::1", else 0.

Example

is_ipv6_loopback("::1")  ->  1
is_ipv6_loopback("::2")  ->  0

Input format

addr: a NUL-terminated IPv6 address string.

Output format

1 if addr is exactly "::1", else 0.

Constraints

Exact string match against "::1".

Starter code

#include <string.h>

int is_ipv6_loopback(const char *addr) {
    /* TODO */
    return 0;
}

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