networking · beginner · ~15 min

Is it an internet family?

Identify the IP address families.

Challenge

Tell whether an address family is one of the IP families.

Task

Implement int is_inet_family(int af).

Input

  • af: an address-family constant (e.g. AF_INET, AF_INET6, AF_UNIX).

Output

Return 1 if af is AF_INET or AF_INET6, else 0.

Example

is_inet_family(AF_INET)   ->  1
is_inet_family(AF_INET6)  ->  1
is_inet_family(AF_UNIX)   ->  0

Input format

af: an address-family constant.

Output format

1 if af is AF_INET or AF_INET6, else 0.

Constraints

AF_INET and AF_INET6 are IP families; AF_UNIX is not.

Starter code

#include <sys/socket.h>

int is_inet_family(int af) {
    /* TODO */
    return 0;
}

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