内容简介
#include <sys/types.h>%uA0#include <sys/socket.h>
int getsockopt(int%uA0s, int%uA0level, int%uA0optname,%uA0void *optval, socklen_t *optlen)
int setsockopt(int%uA0s, int%uA0level, int%uA0optname,%uA0const void *optval, socklen_t%uA0optlen)
描述
getsockopt() and%uA0setsockopt() manipulate the%uA0options%uA0associated with a socket. Options may exist at multiple protocol levels they are always present at the uppermost%uA0socket%uA0level.When manipulating socket options the level at which the option resides and the name of the option must be specified. To manipulate options at the socket level,%uA0level%uA0is specified as%uA0SOL_SOCKET. To manipulate options at any other level the protocol number of the appropriate protocol controlling the option is supplied. For example, to indicate that an option is to be interpreted by the%uA0TCP%uA0protocol,%uA0level%uA0should be set to the protocol number of%uA0TCP see%uA0getprotoent(3).
The parameters%uA0optval%uA0and%uA0optlen%uA0are used to access option values for%uA0setsockopt(). Forgetsockopt() they identify a buffer in which the value for the requested option(s) are to be returned. For%uA0getsockopt(),%uA0optlen%uA0is a value-result parameter, initially containing the size of the buffer yiibaied to by%uA0optval, and modified on return to indicate the actual size of the value returned. If no option value is to be supplied or returned,%uA0optval%uA0may be NULL.
Optname%uA0and any specified options are passed uninterpreted to the appropriate protocol module for interpretation. The include file%uA0<sys/socket.h>%uA0contains definitions for socket level options, described below. Options at other protocol levels vary in format and name consult the appropriate entries in section 4 of the manual.
Most socket-level options utilize an%uA0int%uA0parameter for%uA0optval. For%uA0setsockopt(), the parameter should be non-zero to enable a boolean option, or zero if the option is to be disabled.
%uA0
For a description of the available socket options see%uA0socket(7) and the appropriate protocol man pages.
%uA0
返回值
On success, zero is returned. On error, -1 is returned, and%uA0errno%uA0is set appropriately.错误
标签 | 描述 |
---|---|
EBADF | The argument%uA0s%uA0is not a valid descriptor. |
EFAULT | The address yiibaied to by%uA0optval%uA0is not in a valid part of the process address space. For%uA0getsockopt(), this error may also be returned if%uA0optlen%uA0is not in a valid part of the process address space. |
EINVAL | optlen%uA0invalid in%uA0setsockopt(). |
ENOPROTOOPT | |
%uA0 | The option is unknown at the level indicated. |
ENOTSOCK | The argument%uA0s%uA0is a file, not a socket. |
遵循于
SVr4, 4.4BSD (these system calls first appeared in 4.2BSD),%uA0POSIX.1-2001.