setsockopt()
PROTOTYPE
#include <sockets.h>
int setsockopt(int socket, int level, int optname, void *optval, int optlen);
DESCRIPTION
setsockopt() sets various options that control socket or protocol behavior. socket is a handle returned by socket(). level indicates the software layer controlled by the option. optname specifies the selected option. optval and optlen point to a parameter value and a parameter size, respectively, that are read by setsockopt(). The Supported options are listed here.
If successful, setsockopt() returns 0. Otherwise, it sets errno and returns -1.
ERROR CODES
| EFAULT | optval is NULL or optlen is not correct for the specified option. |
| EINVAL | optval has an invalid value. |
| ENETDOWN | TargetTCP has not been initialized. |
| ENOPROTOOPT | The combination of level and optname is unsupported. |
| ENOTCONN | The socket is not connected and the SO_KEEPALIVE option was requested. |
| ENOTSOCK | socket is not a valid socket handle. |
| EOPNOTSUPP | Operation not supported, socket type is not correct for specified option. |
EXAMPLE
int sock, timeo;
/*-------------------------------------------------------------------*/
/* Reduce the receive timeout from indefinite to 10 seconds. */
/*-------------------------------------------------------------------*/
timeo = 10000;
rc = setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo));
if (rc < 0) goto error;