setsockopt()

set socket options 

Function


SYNOPSIS

#include <sys/socket.h>

setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen);


DESCRIPTION

The setsockopt() function manipulates options associated with a socket. Options can exist at multiple protocol levels. However, the options are always present at the uppermost socket level. Options affect socket operations, such as the routing of packets, out-of-band data transfer, and so on.

The level argument specifies the protocol level at which the option resides. To set options at the socket level, specify the level argument as SOL_SOCKET. To set options at other levels, supply the appropriate protocol number for the protocol controlling the option. For example, to indicate that an option is interpreted by the TCP (Transport Control Protocol), set level to the protocol number of TCP.

The following options are supported for setsockopt():

SO_DEBUG  

Provides the ability to turn on recording of debugging information. This option takes an int value in the optval argument. This is a BOOL option.

SO_BROADCAST  

Permits sending of broadcast messages, if this is supported by the protocol. This option takes an int value in the optval argument. This is a BOOL option.

SO_REUSEADDR  

Specifies that the rules used in validating addresses supplied to bind() should allow reuse of local addresses, if this is supported by the protocol. This option takes an int value in the optval argument. This is a BOOL option.

SO_KEEPALIVE  

Keeps connections active by enabling periodic transmission of messages, if this is supported by the protocol.

If the connected socket fails to respond to these messages, the connection is broken and processes writing to that socket are notified with an ENETRESET errno. This option takes an int value in the optval argument. This is a BOOL option.

SO_LINGER  

Specifies whether the socket lingers on close() if data is present. If SO_LINGER is set, the system blocks the process during close() until it can transmit the data or until the end of the interval indicated by the l_linger member, whichever comes first. If SO_LINGER is not specified, and close() is issued, the system handles the call in a way that allows the process to continue as quickly as possible. This option takes a linger structure in the optval argument.

SO_OOBINLINE  

Specifies whether the socket leaves received out-of-band data (data marked urgent) in line. This option takes an int value in optval argument. This is a BOOL option.

SO_SNDBUF  

Sets send buffer size information. This option takes an int value in the optval argument.

SO_RCVBUF  

Sets receive buffer size information. This option takes an int value in the optval argument.

SO_DONTROUTE  

Specifies whether outgoing messages bypass the standard routing facilities. The destination must be on a directly-connected network, and messages are directed to the appropriate network interface according to the destination address. The effect, if any, of this option depends on what protocol is in use. This option takes an int value in the optval argument. This is a BOOL option.

TCP_NODELAY  

Specifies whether the Nagle algorithm used by TCP for send coalescing is to be disabled. This option takes an int value in the optval argument. This is a BOOL option.

For boolean options, a zero value indicates that the option is disabled and a non-zero value indicates that the option is enabled.


PARAMETERS

s 

Specifies a socket for which an option should be set.

level 

Identifies whether the operation applies to the socket itself or to the underlying protocol being used. The socket itself is identified by the symbolic constant SOL_SOCKET. Other protocol levels require the protocol number for the appropriate protocol controlling the option.

optname 

Specifies a single option to which the request applies.

optval 

Specifies a value for the option.

optlen 

Specifies the length of the option value.


RETURN VALUES

If successful, setsockopt() returns a zero. If a failure occurs, it returns a value of -1 and sets errno to one of the following values:

EBADF 

s is not a valid descriptor

ENOTSOCK 

s is not a socket descriptor

ENOPROTOOPT 

optname is unknown at indicated level

EFAULT 

optval is an invalid pointer


CONFORMANCE

UNIX 98, with exceptions.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

The following BSD options are not supported: SO_ACCEPTCONN, SO_RCVLOWAT, SO_RCVTIMEO, SO_SNDLOWAT, SO_SNDTIMEO, SO_TYPE.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
close(), getsockopt(), ioctl(), read(), socket()


PTC MKS Toolkit 10.5 Documentation Build 40.