#define SOL_SOCKET 1 #define SO_ACCEPTCONN 1 #define SO_ERROR 5 #define SO_SNDBUF 13 #define SO_TYPE 16 #define SO_PEERCRED 18 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_ACCEPTCONNval 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_ERRORval 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_SNDBUFval 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_TYPEval 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.
SO_PEERCREDval points to a struct of three uint32_t values, the pid,
uid, and gid of the peer.
The syscall returns 0 on success or -1 on failure, with the errno:
EBADFDfd was not open, or is not a socket.
EACCESval did not point to valid memory.
EINVALThe passed name or level were not valid.