setsockopt

setsockopt, and the corresponding getsockopt, can be used to get and set options for a socket. Use getsockopt to determine socket options. Use setsockopt to set socket options. The new value remains until it is modified again. The optval parameter points to a buffer that specifies the option value according to the option name (optname). The optlen parameter indicates the length of buffer pointed to by optval.  It is used in various ways depending on the specific option. In some cases, it is the length of the option value to be set.

Syntax

int setsockopt(
    SOCKET s,
    int level,
    int optname,
    const char *optval,
    int optlen
);

Parameters

s

Socket descriptor.

level

The layer of the network for which the option is targeted:

optname

Socket option based on the value of level. Some values for the optname parameter are not supported. See the Remarks section below.

optval

Pointer to a buffer to where the option value is stored. Its proper length depends on the type of information being set as specified in the optname field.

optlen

Size, in bytes, of the buffer at optval.

Return Value

0 (zero) if the function succeeds, SOCKET_ERROR if the function fails

Use WSAGetLastError to retrieve a specific error code.

Remarks

Some values for the optname parameter are not supported. The following sections list the options, by socket type, that are supported.

 

SOL_SOCKET level options:

 

IPPROTO_TCP level options:

 

IPPROTO_IP level options:

 

IPPROTO_IPV6 level options:

NOTE: None of the options for the IPPROTO_RM, NSPROTO_IPX, SOL_APPLETALK, and SOL_IRLMP socket types are supported.

Custom RTX64 socket options:

Option Value Description
SO_SND_DGRAMS 0x100B Maximum count of send datagrams on non-TCP socket (default 32)
SO_RCV_DGRAMS 0x100C Maximum count of receive datagrams on non-TCP socket (default 32)
TCP_PROVIDE_TIMESTAMPS 13 Turn ON/OFF Time stamp (default off)
TCP_ACKDELAYTIME 23 Set Ack Delay time (default 200ms)
TCP_ACKNSEG 24 Turn ON/OFF Selective Acknolwlegements (default off)

Requirements

Minimum Supported Version RTX64 2013
Header Winsock2.h
Library RtTcpip.lib