networking · beginner · ~15 min
Recognise the stream socket type constant.
Recognise the TCP (stream) socket-type constant.
Implement int is_stream_socket(int type).
type: a socket-type constant (e.g. SOCK_STREAM, SOCK_DGRAM).Return 1 if type is SOCK_STREAM (TCP), else 0.
is_stream_socket(SOCK_STREAM) -> 1
is_stream_socket(SOCK_DGRAM) -> 0
type: a socket-type constant.
1 if type is SOCK_STREAM, else 0.
Compare against SOCK_STREAM.
#include <sys/socket.h>
int is_stream_socket(int type) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.