getsockopt(2N) getsockopt(2N)NAME getsockopt, setsockopt - get and set options on sockets SYNOPSIS #include <sys/types.h> #include <sys/socket.h> int getsockopt(s, level, optname, optval, optlen) int s, level, optname; char *optval; int *optlen; int setsockopt(s, level, optname, optval, optlen) int s, level, optname; char *optval; int optlen; DESCRIPTION getsockopt and setsockopt manipulate options associated with a socket. Upon successful completion, both getsockopt and setsockopt return 0. A return value of -1 indicates failure. Options can exist at multiple protocol levels; they are always present at the uppermost ``socket'' level. When manipulating socket options, you must specify the level at which the option resides and the name of the option. To manipulate options at the ``socket'' level, specify level as SOL_SOCKET. To manipulate options at any other level, supply the protocol number of the appropriate protocol controlling the option. For example, to indicate that an option is to be interpreted by the Transmission Control Protocol (TCP), set level to the protocol number of TCP (see getprotoent(3N)). The parameters optval and optlen are used to access option values for setsockopt. For getsockopt they identify a buffer in which the value of the requested option(s) is to be returned. For getsockopt, optlen is a value-result parameter, initially containing the size of the buffer pointed to by optval, and modified on return to indicate the actual size of the value returned. If no option value is to be supplied or returned, optval can be supplied as 0. optname and any specified options are passed uninterpreted to the appropriate protocol module for interpretation. The include file <sys/socket.h> contains definitions for socket-level options (see socket(2N)). Options at other protocol levels vary in format and name; consult the appropriate entries in Section 5 of this manual. (Appropriate entries are marked (5P).) January 1992 1
getsockopt(2N) getsockopt(2N)STATUS MESSAGES AND VALUES When a value of -1 is returned, errno contains one of these values: EBADF The argument s is not a valid descriptor. ENOTSOCK The argument s is a file, not a socket. ENOPROTOOPT The option is unknown. EFAULT The options are not in a valid part of the process address space. SEE ALSO getsockname(2N), socket(2N), getprotoent(3N). 2 January 1992