IPPROTO_TCP socket options

The following table describes IPPROTO_TCP socket options that apply to sockets created for the IPv4 and IPv6 address families (AF_INET and AF_INET6) with the protocol parameter to the socket function specified as TCP (IPPROTO_TCP). See the getsockopt and setsockopt function reference pages for more information on getting and setting socket options.

To enumerate protocols and discover supported properties for each installed protocol, use the WSAEnumProtocols, WSCEnumProtocols, or WSCEnumProtocols32 function.

Options

Option Get Set Optval type Description
TCP_BSDURGENT yes yes DWORD (Boolean) If TRUE, the service provider implements the Berkeley Software Distribution (BSD) style (default) for handling expedited data. This option is the inverse of the TCP_EXPEDITED_1122 option. This option can be set on the connection only once. Once this option is set on, this option cannot be turned off. This option is not required to be implemented by service providers. The option is enabled (set to TRUE) by default.
TCP_EXPEDITED_1122 yes yes DWORD (Boolean) If TRUE, the service provider implements the expedited data as specified in RFC-1222. Otherwise, the Berkeley Software Distribution (BSD) style (default) is used. This option can be set on the connection only once. Once this option is set on, this option cannot be turned off. This option is not required to be implemented by service providers.
TCP_FAIL_CONNECT_ON_ICMP_ERROR yes yes DWORD (Boolean) If TRUE, a connect API call will return upon reception of an ICMP error with value WSAEHOSTUNREACH. The source address of the error will then be available via the TCP_ICMP_ERROR_INFO socket option. If FALSE, the socket behaves normally. The default is disabled (set to FALSE). For type-safety, you should use the WSAGetFailConnectOnIcmpError and WSASetFailConnectOnIcmpError functions instead of using the socket option directly.
TCP_ICMP_ERROR_INFO yes no ICMP_ERROR_INFO Retrieves the info of an ICMP error received by the TCP socket during a failed connect call. Only valid on a TCP socket where TCP_FAIL_CONNECT_ON_ICMP_ERROR has previously been enabled, and connect has returned WSAEHOSTUNREACH. The query is non-blocking. If queried successfully and the returned optlen value is 0, then no ICMP error has been received since the last connect call. If an ICMP error was received, its info will be available until connect is called again. The info is returned as an ICMP_ERROR_INFO structure. For type-safety, you should use the WSAGetIcmpErrorInfo function instead of using the socket option directly.
TCP_KEEPCNT yes yes DWORD Gets or sets the number of TCP keep alive probes that will be sent before the connection is terminated. It is illegal to set TCP_KEEPCNT to a value greater than 255.
TCP_MAXRT yes yes DWORD If this value is non-negative, it represents the desired connection timeout in seconds. If it is -1, it represents a request to disable connection timeout (i.e. the connection will retransmit forever). If the connection timeout is disabled, the retransmit timeout increases exponentially for each retransmission up to its maximum value of 60sec and then stays there.
TCP_NODELAY yes yes DWORD (Boolean) Enables or disables the Nagle algorithm for TCP sockets. This option is disabled (set to FALSE) by default.
TCP_TIMESTAMPS yes yes DWORD (Boolean) Enables or disables RFC 1323 time stamps. Note that there is also a global configuration for timestamps (default is off), "Timestamps" in (set/get)-nettcpsetting. Setting this socket option overrides that global configuration setting.
TCP_FASTOPEN yes yes DWORD (Boolean) Enables or disables RFC 7413 TCP Fast Open, which enables you to start sending data during the three-way handshake phase of opening a connection. Note that to make use of fast opens, you should use ConnectEx to make the initial connection, and specify data in that function's lpSendBuffer parameter to be transferred during the handshake process. Some of the data in lpSendBuffer will be transferred under the Fast Open protocol.
TCP_KEEPIDLE yes yes DWORD Gets or sets the number of seconds a TCP connection will remain idle before keepalive probes are sent to the remote.
[!Note]
This option is available starting with Windows 10, version 1709.

TCP_KEEPINTVL yes yes DWORD Gets or sets the number of seconds a TCP connection will wait for a keepalive response before sending another keepalive probe.
[!Note]
This option is available starting with Windows 10, version 1709.

Windows support for IPPROTO_TCP options

Option Windows 10 Windows 7 Windows Server 2008 Windows Vista
TCP_BSDURGENT x x x x
TCP_EXPEDITED_1122 x x x x
TCP_KEEPCNT Starting with Windows 10, version 1703
TCP_MAXRT x x x x
TCP_NODELAY x x x x
TCP_TIMESTAMPS x x x x
TCP_FASTOPEN Starting with Windows 10, version 1607

  Option Windows Server 2003 Windows XP Windows 2000 Windows NT4 Windows 9x/Me
TCP_BSDURGENT x x x x
TCP_EXPEDITED_1122 x x x
TCP_KEEPCNT
TCP_MAXRT
TCP_NODELAY x x x x
TCP_TIMESTAMPS
TCP_FASTOPEN

Remarks

In the Microsoft Windows Software Development Kit (SDK) released for Windows Vista and later, the organization of header files has changed and IPPROTO_TCP level is defined in the Ws2def.h header file which is automatically included in the Winsock2.h header file. The IPPROTO_TCP socket options, with the exception of TCP_BSDURGENT, are defined in the Ws2ipdef.h header file which is automatically included in the Ws2tcpip.h header file. The TCP_BSDURGENT option for historic reasons is defined in the Mswsock.h header file. The Ws2def.h and Ws2ipdef.h header files should never be used directly.

Requirements

Header
Ws2def.h (include Winsock2.h);
Winsock2.h on Windows Server 2003, Windows XP and Windows 2000