SYS_SETSOCKOPT


Sets the options associated with a socket.

Arguments:

1st Socket descriptor.
2nd Protocol level where the options described by 3rd argument are present.
To manipulate options at the socket level, SOL_SOCKET is used. 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 TCP protocol, 2nd argument should be set to the protocol number of TCP.
3rd Option to retrieve. For socket level (SOL_SOCKET) options it may be one of the following values:
SO_DEBUG Socket debugging. Only allowed for processes with the CAP_NET_ADMIN capability or an effective user ID of 0.
SO_REUSEADDR Indicates that the rules used in validating addresses supplied in a SYS_BIND call should allow reuse of local addresses. For PF_INET sockets this means that a socket may bind, except when there is an active listening socket bound to the address. When the listening socket is bound to INADDR_ANY with a specific port then it is not possible to bind to this port for any local address.
SO_TYPE *to be documented*
SO_DONTROUTE Don't send via a gateway, only send to directly connected hosts. The same effect can be achieved by setting the MSG_DONTROUTE flag on a socket SYS_SEND operation. Expects an integer boolean flag.
SO_BROADCAST Set or get the broadcast flag. When enabled, datagram sockets receive packets sent to a broadcast address and they are allowed to send packets to a broadcast address. This option has no effect on stream-oriented sockets.
SO_SNDBUF Sets or gets the maximum socket send buffer in bytes. The kernel doubles this value (to allow space for bookkeeping overhead) when it is set using SYS_SETSOCKOPT, and this doubled value is returned by SYS_GETSOCKOPT. The default value is set by the wmem_default sysctl and the maximum allowed value is set by the wmem_max sysctl. The minimum (doubled) value for this option is 2048.
SO_RCVBUF Sets or gets the maximum socket receive buffer in bytes. The kernel doubles this value (to allow space for bookkeeping overhead) when it is set using SYS_SETSOCKOPT, and this doubled value is returned by SYS_GETSOCKOPT. The default value is set by the rmem_default sysctl and the maximum allowed value is set by the rmem_max sysctl. The minimum (doubled) value for this option is 256.
SO_SNDBUFFORCE (since Linux 2.6.14)
Using this socket option, a privileged (CAP_NET_ADMIN) process can perform the same task as SO_SNDBUF, but the wmem_max limit can be overridden.
SO_RCVBUFFORCE (since Linux 2.6.14)
Using this socket option, a privileged (CAP_NET_ADMIN) process can perform the same task as SO_RCVBUF, but the rmem_max limit can be overridden.
SO_KEEPALIVE Enable sending of keep-alive messages on connection-oriented sockets. Expects an integer boolean flag.
SO_OOBINLINE If this option is enabled, out-of-band data is directly placed into the receive data stream. Otherwise out-of-band data is only passed when the MSG_OOB flag is set during receiving.
SO_PRIORITY Set the protocol-defined priority for all packets to be sent on this socket. Linux uses this value to order the networking queues: packets with a higher priority may be processed first depending on the selected device queueing discipline. For IP level , this also sets the IP type-of-service (TOS) field for outgoing packets. Setting a priority outside the range 0 to 6 requires the CAP_NET_ADMIN capability.
SO_LINGER Set or gets the SO_LINGER option. The argument is a linger structure.

struc linger
{
.l_onoff  rd 1 ; linger active
.l_linger rd 1 ; how many seconds to linger for
}

When enabled, a sys_close or SYS_SHUTDOWN will not return until all queued messages for the socket have been successfully sent or the linger timeout has been reached. Otherwise, the call returns immediately and the closing is done in the background. When the socket is closed as part of sys_exit, it always lingers in the background.
SO_BSDCOMPAT This option is obsolete Linux will generate a kernel warning (printk()) if a program uses this option.
SO_PASSCRED Enable or disable the receiving of the SCM_CREDENTIALS control message. For more information see man 7 unix.
SO_RCVLOWAT Specify the minimum number of bytes in the buffer until the socket layer will pass the data to the user on receiving. This value is initialised to 1. SO_RCVLOWAT is changeable only since Linux 2.4. The sys_select and sys_poll system calls currently do not respect the SO_RCVLOWAT setting on Linux, and mark a socket readable when even a single byte of data is available. A subsequent read from the socket will block until SO_RCVLOWAT bytes are available.
SO_SNDLOWAT This option is not implemented and SYS_SETSOCKOPT will always fail with -ENOPROTOOPT.
SO_RCVTIMEO Specify the receiving timeouts until reporting an error. The parameter is a timeval struct. If an input function blocks for this period of time, and data has been received, the return value of that function will be the amount of data transferred; if no data has been transferred and the timeout has been reached then -1 is returned with -EAGAIN or -EWOULDBLOCK just as if the socket was specified to be nonblocking. If the timeout is set to zero (the default) then the operation will never timeout.
SO_SNDTIMEO Specify the sending timeouts until reporting an error. The parameter is a timeval struct. If an output function blocks for this period of time, and data has been sent, the return value of that function will be the amount of data transferred; if no data has been transferred and the timeout has been reached then -1 is returned with -EAGAIN or -EWOULDBLOCK just as if the socket was specified to be nonblocking. If the timeout is set to zero (the default) then the operation will never timeout.
4th Pointer to a buffer containing parameters for the option specified in 3rd argument.
5th Size of the buffer pointed by 4th argument.

Return values

If the system call succeeds the return value is 0.
If the system call fails the return value is one of the following errno values:

-EBADF The 1st argument is not a valid descriptor.
-EFAULT The address pointed to by 4th argument is not in a valid part of the process address space.
-ENOPROTOOPT The option is unknown at the level indicated.
-ENOTSOCK The 1st argument is a file, not a socket.

Remarks

n/a

Compatibility

n/a