networking · beginner · ~15 min
Map socket type to reliability.
TCP (SOCK_STREAM) provides reliable, ordered delivery; UDP (SOCK_DGRAM) does not. Map a socket type to whether it is reliable.
Implement int is_reliable(int socktype) that returns 1 for SOCK_STREAM, otherwise 0.
One int socktype (e.g. SOCK_STREAM, SOCK_DGRAM).
Returns 1 for SOCK_STREAM, else 0.
is_reliable(SOCK_STREAM) -> 1
is_reliable(SOCK_DGRAM) -> 0
One socket-type constant socktype.
1 if socktype is SOCK_STREAM, else 0.
SOCK_STREAM (TCP) is reliable; SOCK_DGRAM (UDP) is not.
#include <sys/socket.h>
int is_reliable(int socktype) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.