GetIcmpStatistics 関数 (iphlpapi.h)

GetIcmpStatistics 関数は、ローカル コンピューターの IPv4 統計のインターネット制御メッセージ プロトコル (ICMP) を取得します。

構文

IPHLPAPI_DLL_LINKAGE ULONG GetIcmpStatistics(
  [out] PMIB_ICMP Statistics
);

パラメーター

[out] Statistics

ローカル コンピューターの ICMP 統計を受け取る MIB_ICMP 構造体へのポインター。

戻り値

関数が成功した場合、戻り値はNO_ERROR。

関数が失敗した場合、戻り値は次のいずれかのエラー コードになります。

リターン コード 説明
ERROR_INVALID_PARAMETER
pStats パラメーターが NULL であるか、GetIcmpStatisticspStats パラメーターが指すメモリに書き込むことができません。
その他
FormatMessage 関数を使用して、返されたエラーのメッセージ文字列を取得します。

注釈

GetIcmpStatistics 関数は、ローカル コンピューター上の IPv4 の ICMP 統計を返します。 Windows XP 以降では、 GetIpStatisticsEx を使用して、ローカル コンピューター上の IPv4 または IPv6 の ICMP 統計を取得できます。

次の例では、ローカル コンピューターの IPv4 統計の ICMP を取得し、返されたデータからいくつかの情報を出力します。

#ifndef UNICODE
#define UNICODE
#endif

#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()
{

    DWORD dwRetVal = 0;
    PMIB_ICMP pIcmpStats;

    pIcmpStats = (MIB_ICMP *) MALLOC(sizeof (MIB_ICMP));
    if (pIcmpStats == NULL) {
        wprintf(L"Error allocating memory\n");
        return 1;
    }

    dwRetVal = GetIcmpStatistics(pIcmpStats);
    if (dwRetVal == NO_ERROR) {
        wprintf(L"Number of incoming ICMP messages: %ld\n",
                pIcmpStats->stats.icmpInStats.dwMsgs);
        wprintf(L"Number of incoming ICMP errors received: %ld\n",
                pIcmpStats->stats.icmpInStats.dwErrors);
        wprintf(L"Number of outgoing ICMP messages: %ld\n",
                pIcmpStats->stats.icmpOutStats.dwMsgs);
        wprintf(L"Number of outgoing ICMP errors sent: %ld\n",
                pIcmpStats->stats.icmpOutStats.dwErrors);
    } else {
        wprintf(L"GetIcmpStatistics failed with error: %ld\n", dwRetVal);
    }

    if (pIcmpStats)
        FREE(pIcmpStats);

    return 0;
}

要件

要件
サポートされている最小のクライアント Windows 2000 Professional [デスクトップ アプリ |UWP アプリ]
サポートされている最小のサーバー Windows 2000 Server [デスクトップ アプリ |UWP アプリ]
対象プラットフォーム Windows
ヘッダー iphlpapi.h
Library Iphlpapi.lib
[DLL] Iphlpapi.dll

こちらもご覧ください

GetIpStatistics

GetIpStatisticsEx

GetTcpStatistics

GetUdpStatistics

IP ヘルパー関数リファレンス

IP ヘルパーの開始ページ

MIB_ICMP