9.85 getsockopt/setsockopt

#define SOL_SOCKET 1

#define SO_ACCEPTCONN 1
#define SO_ERROR      5
#define SO_SNDBUF     13
#define SO_TYPE       16

int getsockopt(int fd, int level, int name, void *val, socklen_t *len);
int setsockopt(int fd, int level, int name, void *val, socklen_t len);

This syscall gets or sets the option passed on name for the socket level passed on level, and writes or fetches data from val with the length passed on len.

Right now, SOL_SOCKET is the only supported socket level.

name can be one of:

SO_ACCEPTCONN

val will point to an uint32_t. 1 will be written there if the passed socket is listening, and 0 if it is not/cannot listen due to protocol. getsockopt only.

SO_ERROR

val will point to an uint32_t. The value will be written with the present socket error if any, or 0 if none are present. getsockopt only.

SO_SNDBUF

val will point to an uint32_t. If getting the value, the current send-buffer size will be returned, else, it setting it, the passed size will be used for the same buffer.

SO_TYPE

val will point to an uint32_t. The type of socket will be returned in that variable in the same format as see socket. getsockopt only.

The syscall returns 0 on success or -1 on failure, with the errno:

EBADFD

fd was not open, or is not a socket.

EACCES

val did not point to valid memory.

EINVAL

The passed name or level were not valid.