本文介绍了以编程方式确定 Win32 上 TCP 连接的数据包丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 winsock 创建 TCPIP 套接字的 win32 应用程序.

这很好,除了在某些情况下我想知道实际套接字的统计信息.诸如发送的数据包、接收的数据包、发送的总字节数等内容.但我想看到的最重要的数据是数据包丢失.

我一直无法找到获取此类数据的正确调用,我查看了getsockopt,但找不到获取此类数据的好方法.

有没有办法在 windows API 上获取 TCP 套接字的低级统计信息?

作为参考,我使用的是 Windows 7(64 位版本)

谢谢!

解决方案

你可以试试 GetTcpStatisticsEx.它返回 MIB_TCPSTATS 结构,其中包含重传计数:

typedef struct _MIB_TCPSTATS {DWORD dwRtoAlgorithm;DWORD dwRtoMin;DWORD dwRtoMax;DWORD dwMaxConn;DWORD dwActiveOpens;DWORD dwPassiveOpens;DWORD dwAttemptFails;DWORD dwEstabResets;DWORD dwCurrEstab;DWORD dwInSegs;DWORD dwOutSegs;DWORD dwRetransSegs;//<==========DWORD dwInErrs;DWORD dwOutRsts;DWORD dwNumConns;MIB_TCPSTATS;

dwRetransSegs
 类型:DWORD

 重传的段数.

I have a win32 application that uses winsock to create TCPIP sockets.

This is great, except in some cases I would like to know statistics on the actual socket. Stuff like packets sent, received, total bytes sent, etc. But the most important piece of data I want to see is packet loss.

I have not been able to find the right call to get such data, I have looked at getsockopt and cannot find a good way to get such data.

Is there a way to get low level statistics of a TCP socket on the windows API?

For reference I am using Windows 7 (64-bit version)

Thank you!

解决方案

You can try GetTcpStatisticsEx. It returns the MIB_TCPSTATS structure, which contains among other things the retransmission count:

typedef struct _MIB_TCPSTATS {
  DWORD dwRtoAlgorithm;
  DWORD dwRtoMin;
  DWORD dwRtoMax;
  DWORD dwMaxConn;
  DWORD dwActiveOpens;
  DWORD dwPassiveOpens;
  DWORD dwAttemptFails;
  DWORD dwEstabResets;
  DWORD dwCurrEstab;
  DWORD dwInSegs;
  DWORD dwOutSegs;
  DWORD dwRetransSegs;    // <=========
  DWORD dwInErrs;
  DWORD dwOutRsts;
  DWORD dwNumConns;
} MIB_TCPSTATS;

这篇关于以编程方式确定 Win32 上 TCP 连接的数据包丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 22:09