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.

**IPPROTO\_TCP Socket 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_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](https://tools.ietf.org/html/rfc7413) 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](/windows/desktop/api/Mswsock/nc-mswsock-lpfn_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 Windows Server 2003 Windows XP Windows 2000 Windows NT4 Windows 9x/Me
TCP_BSDURGENT x x x x x x x x
TCP_EXPEDITED_1122 x x x x x x x
TCP_KEEPCNT Starting with Windows 10, version 1703
TCP_MAXRT x x x x
TCP_NODELAY x x x x x x x x
TCP_TIMESTAMPS x x x x
TCP_FASTOPEN Starting with Windows 10, version 1607

 

Remarks

On 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