GetTcpStatistics-Funktion (iphlpapi.h)

Die GetTcpStatistics-Funktion ruft die TCP-Statistiken für den lokalen Computer ab.

Syntax

IPHLPAPI_DLL_LINKAGE ULONG GetTcpStatistics(
  [out] PMIB_TCPSTATS Statistics
);

Parameter

[out] Statistics

Ein Zeiger auf eine MIB_TCPSTATS Struktur, die die TCP-Statistiken für den lokalen Computer empfängt.

Rückgabewert

Wenn die Funktion erfolgreich ist, wird der Rückgabewert NO_ERROR.

Wenn die Funktion fehlschlägt, ist der Rückgabewert einer der folgenden Fehlercodes.

Rückgabecode Beschreibung
ERROR_INVALID_PARAMETER
Der pStats-Parameter ist NULL, oder GetTcpStatistics kann nicht in den Speicher schreiben, auf den der pStats-Parameter verweist.
Andere
Verwenden Sie die FormatMessage-Funktion , um die Nachrichtenzeichenfolge für den zurückgegebenen Fehler abzurufen.

Hinweise

Die GetTcpStatistics-Funktion gibt die TCP-Statistiken für IPv4 auf dem aktuellen Computer zurück. Unter Windows XP und höher kann getTcpStatisticsEx verwendet werden, um die TCP-Statistiken für IPv4 oder IPv6 abzurufen.

Beispiele

Im folgenden Beispiel werden die TCP-Statistiken für den lokalen Computer abgerufen und einige Werte aus den zurückgegebenen Daten ausgegeben.

//#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>
#include <stdio.h>

#pragma comment(lib, "iphlpapi.lib")

#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x)) 
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))

/* Note: could also use malloc() and free() */

int main()
{
    PMIB_TCPSTATS pTCPStats;
    DWORD dwRetVal = 0;

    pTCPStats = (MIB_TCPSTATS*) MALLOC (sizeof(MIB_TCPSTATS));
    if (pTCPStats == NULL) {
        printf("Error allocating memory\n");
        return 1;
    }

    if ((dwRetVal = GetTcpStatistics(pTCPStats)) == NO_ERROR) {
      printf("\tActive Opens: %ld\n", pTCPStats->dwActiveOpens);
      printf("\tPassive Opens: %ld\n", pTCPStats->dwPassiveOpens);
      printf("\tSegments Recv: %ld\n", pTCPStats->dwInSegs);
      printf("\tSegments Xmit: %ld\n", pTCPStats->dwOutSegs);
      printf("\tTotal # Conxs: %ld\n", pTCPStats->dwNumConns);
    }
    else {
      printf("GetTcpStatistics failed with error: %ld\n", dwRetVal);
      
      LPVOID lpMsgBuf;
      if (FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | 
        FORMAT_MESSAGE_FROM_SYSTEM | 
        FORMAT_MESSAGE_IGNORE_INSERTS,
        NULL,
        dwRetVal,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
        (LPTSTR) &lpMsgBuf,
        0,
        NULL )) {
        printf("\tError: %s", lpMsgBuf);
      }
      LocalFree( lpMsgBuf );
    }

    if (pTCPStats)
        FREE (pTCPStats);
}

Anforderungen

   
Unterstützte Mindestversion (Client) Windows 2000 Professional [nur Desktop-Apps]
Unterstützte Mindestversion (Server) Windows 2000 Server [nur Desktop-Apps]
Zielplattform Windows
Kopfzeile iphlpapi.h
Bibliothek Iphlpapi.lib
DLL Iphlpapi.dll

Weitere Informationen

GetIcmpStatistics

GetIpStatistics

GetTcpStatisticsEx

GetUdpStatistics

IP-Hilfsfunktionsreferenz

IP-Hilfsprogramm-Startseite

MIB_TCPSTATS