直接上干货吧,查了官方文档才解决的,用了好久时间
TCP_INFO_v1 tcpInfo;
DWORD dversion = 1;
DWORD bytesReturned;
if (WSAIoctl(sock, SIO_TCP_INFO, &dversion,
sizeof(DWORD), &tcpInfo, sizeof(TCP_INFO_v1),
&bytesReturned, NULL, NULL) == SOCKET_ERROR)
{
return false;
}
其中tcpInfo.State 有一下几种状态,对应的含义,在我上一篇文章中有提到
TCPSTATE_CLOSED,
TCPSTATE_LISTEN,
TCPSTATE_SYN_SENT,
TCPSTATE_SYN_RCVD,
TCPSTATE_ESTABLISHED,
TCPSTATE_FIN_WAIT_1,
TCPSTATE_FIN_WAIT_2,
TCPSTATE_CLOSE_WAIT,
TCPSTATE_CLOSING,
TCPSTATE_LAST_ACK,
TCPSTATE_TIME_WAIT,
TCPSTATE_MAX