setsockopt
setsockopt, and the corresponding getsockopt, can 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(
[in] SOCKET s,
[in] int level,
[in] int optname,
[in] const char *optval,
[in] int optlen
);
Parameters
[in] s
The socket descriptor.
[in] level
The layer of the network for which the option is targeted:
- SOL_SOCKET (socket interface level).
- IPPROTO_IP (IP network level for IPv4 sockets).
- IPPROTO_IPV6 (IP network level for IPv6 sockets).
- IPPROTO_TCP (TCP transport level).
[in] optname
The socket option based on the value of level. Some values for the optname parameter are not supported. See the Remarks section below.
[in] optval
A pointer to a buffer to where the option value is stored. Its proper length depends on the information type specified in the optname field.
[in] optlen
The size, in bytes, of the buffer at optval.
Return Value
If the function succeeds, it returns 0 (zero). If the function fails, it returns SOCKET_ERROR. Call WSAGetLastError to retrieve a specific error code.
Remarks
Some values for the optname parameter are not supported. The following section lists the supported options by socket type.
SOL_SOCKET level options:
- SO_RCVBUF
- SO_SNDBUF
- SO_SND_DGRAMS (see Custom wRTOS socket options below)
- SO_RCV_DGRAMS (see Custom wRTOS socket options below)
- SO_BROADCAST
- SO_KEEPALIVE
- SO_LINGER
- SO_REUSEADDR
- SO_OOBINLINE
IPPROTO_TCP level options:
- TCP_NODELAY
- TCP_MAXRT
- TCP_PROVIDE_TIMESTAMPS (see Custom wRTOS socket options below)
- TCP_ACKNSEG (see Custom wRTOS socket options below)
- TCP_ACKDELAYTIME (see Custom wRTOS socket options below)
IPPROTO_IP level options:
- IP_DONTFRAGMENT
- IP_HDRINCL
- IP_TTL
- IP_TOS
- IP_ADD_MEMBERSHIP
- IP_DROP_MEMBERSHIP
- IP_MULTICAST_IF
- IP_MULTICAST_TTL
- IP_ADD_SOURCE_MEMBERSHIP
- IP_DROP_SOURCE_MEMBERSHIP
- IP_BLOCK_SOURCE
- IP_UNBLOCK_SOURCE
- MCAST_JOIN_SOURCE_GROUP
- MCAST_LEAVE_SOURCE_GROUP
- MCAST_BLOCK_SOURCE
- MCAST_UNBLOCK_SOURCE
IPPROTO_IPV6 level options:
- IPV6_HDRINCL
- IPV6_V6ONLY
- IPV6_UNICAST_HOPS
- IPV6_MULTICAST_IF
- IPV6_MULTICAST_HOPS
- IPV6_MULTICAST_LOOP
- IPV6_JOIN_GROUP
- IPV6_LEAVE_GROUP
- MCAST_JOIN_SOURCE_GROUP
- MCAST_LEAVE_SOURCE_GROUP
- MCAST_BLOCK_SOURCE
- MCAST_UNBLOCK_SOURCE
Note: None of the options for the IPPROTO_RM, NSPROTO_IPX, SOL_APPLETALK, and SOL_IRLMP socket types are supported.
| Option | Value | Description |
|---|---|---|
|
SO_SND_DGRAMS |
0x100B |
The maximum count of send datagrams on a non-TCP socket (default 32). |
|
SO_RCV_DGRAMS |
0x100C |
The maximum count of receive datagrams on a non-TCP socket (default 32). |
|
TCP_PROVIDE_TIMESTAMPS |
13 |
Turn on/off Time Stamps (default off). |
|
TCP_ACKDELAYTIME |
23 |
Set Ack Delay time (default 200 ms). |
|
TCP_ACKNSEG |
24 |
Turn on/off Selective Acknowledgments (default off). |
Requirements
| Minimum supported version | Header | Library |
|---|---|---|
|
wRTOS 1.0 SDK |
winsock2.h |
RttcpipApi.lib |