setsockopt
Prototype:
#include <sys/types.h>
#include <sys/socket.h>
int setsockopt(int sd, int level, int optname, const void *optval,
    socklen_t optlen);
General Description: Change the behavior of socket sd. Every option has a value (some options are read- or write-only). You can set each option through optval and optlen. Socket options available for general, IP, TCP, and TCPv6.
Return Value: Zero (0) if everything goes well. If an error occurs, you can find the cause in errno.
Parameters
sd The socket to modify.
level The feature level (SOL_SOCKET, SOL_IP, SOL_TCP, SOL_IPV6).
optname The option to revise.
optval A pointer to the new value.
optlen The length of value in bytes.
Possible Errors
EBADF The argument sd is not a valid descriptor.
ENOTSOCK The argument sd is a file, not a socket.
ENOPROTOOPT The option is unknown at the level indicated.
EFAULT The address pointed to optval is not in a valid part of the process address space.
Examples
const int TTL=128;
/*---Change the time-to-live to 128 hops---*/
if ( setsockopt(sd, SOL_IP, SO_TTL, &TTL, sizeof(TTL)) != 0 )
    perror("setsockopt() failed");