Função GetIpStatistics (iphlpapi.h)
A função GetIpStatistics recupera as estatísticas de IP do computador atual.
Sintaxe
IPHLPAPI_DLL_LINKAGE ULONG GetIpStatistics(
[out] PMIB_IPSTATS Statistics
);
Parâmetros
[out] Statistics
Um ponteiro para uma estrutura MIB_IPSTATS que recebe as estatísticas de IP para o computador local.
Valor retornado
Se a função for bem-sucedida, o valor retornado será NO_ERROR.
Se a função falhar, o valor retornado será um dos códigos de erro a seguir.
Código de retorno | Descrição |
---|---|
|
O parâmetro pStats é NULL ou GetIpStatistics não pode gravar na memória apontada pelo parâmetro pStats . |
|
Use a função FormatMessage para obter a cadeia de caracteres de mensagem para o erro retornado. |
Comentários
A função GetIpStatistics retorna as estatísticas para IPv4 no computador atual. No Windows XP e posterior, o GetIpStatisticsEx pode ser usado para obter as estatísticas de IP para IPv4 ou IPv6.
Exemplos
O exemplo a seguir recupera as estatísticas IPv4 para o computador local e imprime valores dos dados retornados.
#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;
MIB_IPSTATS *pStats;
pStats = (MIB_IPSTATS *) MALLOC(sizeof (MIB_IPSTATS));
if (pStats == NULL) {
wprintf(L"Unable to allocate memory for MIB_IPSTATS\n");
exit(1);
}
dwRetval = GetIpStatistics(pStats);
if (dwRetval != NO_ERROR) {
wprintf(L"GetIpStatistics call failed with %d\n", dwRetval);
exit(1);
} else {
wprintf(L"IP forwarding: \t\t" );
switch (pStats->dwForwarding) {
case MIB_IP_FORWARDING:
wprintf(L"Enabled\n");
break;
case MIB_IP_NOT_FORWARDING:
wprintf(L"Disabled\n");
break;
default:
wprintf(L"unknown value = %d\n", pStats->dwForwarding);
break;
}
wprintf(L"Default initial TTL: \t\t\t\t\t%u\n", pStats->dwDefaultTTL);
wprintf(L"Number of received datagrams: \t\t\t\t%u\n", pStats->dwInReceives);
wprintf(L"Number of received datagrams with header errors: \t%u\n", pStats->dwInHdrErrors);
wprintf(L"Number of received datagrams with address errors: \t%u\n", pStats->dwInAddrErrors);
wprintf(L"Number of datagrams forwarded: \t\t\t\t%ld\n", pStats->dwForwDatagrams);
wprintf(L"Number of received datagrams with an unknown protocol: \t%u\n", pStats->dwInUnknownProtos);
wprintf(L"Number of received datagrams discarded: \t\t%u\n", pStats->dwInDiscards);
wprintf(L"Number of received datagrams delivered: \t\t%u\n", pStats->dwInDelivers);
wprintf(L"Number of outgoing datagrams requested to transmit: \t%u\n", pStats->dwOutRequests);
wprintf(L"Number of outgoing datagrams discarded for routing: \t%u\n", pStats->dwRoutingDiscards);
wprintf(L"Number of outgoing datagrams discarded: \t\t%u\n", pStats->dwOutDiscards);
wprintf(L"Number of outgoing datagrams with no route to destination discarded: %u\n", pStats->dwOutNoRoutes);
wprintf(L"Fragment reassembly timeout: \t\t\t\t%u\n", pStats->dwReasmTimeout);
wprintf(L"Number of datagrams that required reassembly: \t\t%u\n", pStats->dwReasmReqds);
wprintf(L"Number of datagrams successfully reassembled: \t\t%u\n", pStats->dwReasmOks);
wprintf(L"Number of datagrams that could not be reassembled: \t%u\n", pStats->dwReasmFails);
wprintf(L"Number of datagrams fragmented successfully: \t\t%u\n", pStats->dwFragOks);
wprintf(L"Number of datagrams not fragmented and discarded: \t%u\n", pStats->dwFragFails);
wprintf(L"Number of fragments created: \t\t\t\t%u\n", pStats->dwFragCreates);
wprintf(L"Number of interfaces: \t\t\t\t\t%u\n", pStats->dwNumIf);
wprintf(L"Number of IP addresses: \t\t\t\t%u\n", pStats->dwNumAddr);
wprintf(L"Number of routes: \t\t\t\t\t%u\n", pStats->dwNumRoutes);
}
// Free memory allocated for the MIB_IPSTATS structure
if (pStats)
FREE(pStats);
return 0;
}
Requisitos
Cliente mínimo com suporte | Windows 2000 Professional [somente aplicativos da área de trabalho] |
Servidor mínimo com suporte | Windows 2000 Server [somente aplicativos da área de trabalho] |
Plataforma de Destino | Windows |
Cabeçalho | iphlpapi.h |
Biblioteca | Iphlpapi.lib |
DLL | Iphlpapi.dll |
Confira também
Referência de função auxiliar de IP