Windows 10 and above support the SIO_TCP_INFO control code for querying the statistics for a socket handle including the number of retransmissions:
typedef struct _TCP_INFO_v0 {
TCPSTATE State;
ULONG Mss;
ULONG64 ConnectionTimeMs;
BOOLEAN TimestampsEnabled;
ULONG RttUs;
ULONG MinRttUs;
ULONG BytesInFlight;
ULONG Cwnd;
ULONG SndWnd;
ULONG RcvWnd;
ULONG RcvBuf;
ULONG64 BytesOut;
ULONG64 BytesIn;
ULONG BytesReordered;
ULONG BytesRetrans;
ULONG FastRetrans;
ULONG DupAcksIn;
ULONG TimeoutEpisodes;
UCHAR SynRetrans;
} TCP_INFO_v0, *PTCP_INFO_v0;
TCP_INFO_v0 tcpInfo;
ULONG version = 0; // Specify 0 to retrieve the v0 version of this structure.
ULONG bytesReturned;
WSAIoctl(
SocketHandle,
SIO_TCP_INFO,
&version,
sizeof(ULONG),
&tcpInfo,
sizeof(TCP_INFO_v0),
&bytesReturned,
NULL,
NULL
);