Go to the previous, next section.

getsockopt

SYNOPSIS

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);

PARAMETERS

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.

DESCRIPTION

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
Enable/disable the recording of the debug information by the underliying protocol modules. optval is an boolean value (int).

SO_REUSEADDR
Enable/disable local address reuse so that a bind call can reuse old addresses. optval is a boolean value (int).

SO_KEEPALIVE
Enable/disable the "keep connections alive" feature. Using this feature, periodic messages are sent to the remote connection. If the peer machine does not respond to those messages, the connection is broken and the processes using the socket receive a SIGPIPE signal. optval is a boolean value (int).

SO_DONTROUTE
Enable/disable the routing bypass for outgoing message. If enabled, the socket completely bypass the routing facilities of the operating system. optval is a boolean value (int).

SO_LINGER
Linger on close if data present. Without this feature, a 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
Enable/disable the permission of broadcasting packets. optval is a boolean value (int).

SO_OOBINLINE
Enable/disable the reception of out-of-band data as in band data. optval is a boolean value (int).

SO_SNDBUF
Set the buffer size for output. optval is an int.

SO_RCVBUF
Set the buffer size for input. optval is an int.

SO_SNDLOWAT
Set minimum count for output. This count is the mininum number of bytes that must be stored in the send buffer before actually sending them on the network. optval is an int.

SO_RCVLOWAT
Set minimum count for input. This count is the mininum number of bytes that must be received in the receive buffer before returning from a call reading from the socket. optval is an int.

SO_SNDTIMEO
Set timeout for output calls. optval is an struct timeval.

SO_RCVTIMEO
Set timeout for input calls. optval is an struct timeval.

SO_TYPE
For getsockopt only: get the type of socket. optval is an int.

SO_TYPE
For getsockopt only: get the last error on the socket. optval is an int.

RETURN VALUE

On success zero is returned. On error, -1 is returned and errno is set to one of the following values:

Go to the previous, next section.