Go to the previous, next section.
int getsockopt(int s, int level, int optname,
void *optval, int *optlen);
int setsockopt(int s, int level, int optname,
const void *optval, int optlen);
s: [in] the socket we want to work on.
level: [in] the protocol level to access.
optname: [in] the option to access.
optval: for getsockopt, [out] points to the buffer where to
save the option value. For setsockopt, [in] points to the buffer
containing the new option value.
optlen: for getsockopt, [in out] on entry, the maximum
length of optval, on return, the actual length of the option. For
setsockopt, the length of the new option.
The possible values of level are SOL_SOCKET and any valid protocol number. At socket level, a value of zero for the options is boolean flase and a non-zero value is boolean true. The following options are recognized at socket level:
SO_DEBUG
SO_REUSEADDR
bind call can reuse
old addresses. optval is a boolean value (int).
SO_KEEPALIVE
SIGPIPE signal. optval
is a boolean value (int).
SO_DONTROUTE
SO_LINGER
close on
a socket is always performed in a quick non-blocking fashion. However,
when this feature is enabled, the close call will block for a
while if the socket still has data enqueued on the send queue. The call
will block until it is able to send the data or if a specified timeout
value expire. optval is a struct linger structure.
SO_BROADCAST
SO_OOBINLINE
SO_SNDBUF
SO_RCVBUF
SO_SNDLOWAT
SO_RCVLOWAT
SO_SNDTIMEO
struct timeval.
SO_RCVTIMEO
struct timeval.
SO_TYPE
getsockopt only: get the type of socket. optval is an int.
SO_TYPE
getsockopt only: get the last error on the socket.
optval is an int.
On success zero is returned. On error, -1 is returned and errno is
set to one of the following values:
ENOPROTOOPT: the option is not valid for the protocol specified.
EBADF, ENOTSOCK and EFAULT.
Go to the previous, next section.