Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
3.7 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include "StatisticsProviders.h"
  4. #include "ras.h"
  5. #include "rasuip.h"
  6. #include "ndispnp.h"
  7. CLANStatisticsProvider::CLANStatisticsProvider()
  8. {
  9. }
  10. HRESULT CLANStatisticsProvider::Initialize(GUID* pGuid)
  11. {
  12. HRESULT hr = S_OK;
  13. lstrcpy(m_pszDeviceString, L"\\Device\\");
  14. StringFromGUID2(*pGuid, m_pszDeviceString + (sizeof(L"\\Device\\") / sizeof(WCHAR) - 1), 54);
  15. RtlInitUnicodeString(&m_Device, m_pszDeviceString);
  16. return hr;
  17. }
  18. HRESULT CLANStatisticsProvider::FinalRelease()
  19. {
  20. HRESULT hr = S_OK;
  21. return hr;
  22. }
  23. HRESULT CLANStatisticsProvider::GetStatistics(ULONG* pulBytesSent, ULONG* pulBytesReceived, ULONG* pulPacketsSent, ULONG* pulPacketsReceived, ULONG* pulSpeedbps, ULONG* pulUptime)
  24. {
  25. HRESULT hr = S_OK;
  26. NIC_STATISTICS nsNewLanStats;
  27. ZeroMemory(&nsNewLanStats, sizeof(nsNewLanStats));
  28. nsNewLanStats.Size = sizeof(NIC_STATISTICS);
  29. if (NdisQueryStatistics(&m_Device, &nsNewLanStats))
  30. {
  31. if(NULL != pulBytesSent)
  32. {
  33. *pulBytesSent = static_cast<ULONG>(nsNewLanStats.BytesSent);
  34. }
  35. if(NULL != pulBytesReceived)
  36. {
  37. *pulBytesReceived = static_cast<ULONG>(nsNewLanStats.DirectedBytesReceived);
  38. }
  39. if(NULL != pulPacketsSent)
  40. {
  41. *pulPacketsSent = static_cast<ULONG>(nsNewLanStats.PacketsSent);
  42. }
  43. if(NULL != pulPacketsReceived)
  44. {
  45. *pulPacketsReceived = static_cast<ULONG>(nsNewLanStats.DirectedPacketsReceived);
  46. }
  47. if(NULL != pulUptime)
  48. {
  49. *pulUptime = nsNewLanStats.ConnectTime;
  50. }
  51. if(NULL != pulSpeedbps)
  52. {
  53. *pulSpeedbps = nsNewLanStats.LinkSpeed * 100;
  54. }
  55. }
  56. else
  57. {
  58. hr = E_FAIL;
  59. }
  60. return hr;
  61. }
  62. CRASStatisticsProvider::CRASStatisticsProvider()
  63. {
  64. m_pNetRasConnection = NULL;
  65. }
  66. HRESULT CRASStatisticsProvider::Initialize(INetConnection* pNetConnection)
  67. {
  68. HRESULT hr = S_OK;
  69. hr = pNetConnection->QueryInterface(IID_INetRasConnection, reinterpret_cast<void**>(&m_pNetRasConnection));
  70. return hr;
  71. }
  72. HRESULT CRASStatisticsProvider::FinalRelease()
  73. {
  74. HRESULT hr = S_OK;
  75. if(NULL != m_pNetRasConnection)
  76. {
  77. m_pNetRasConnection->Release();
  78. }
  79. return hr;
  80. }
  81. HRESULT CRASStatisticsProvider::GetStatistics(ULONG* pulBytesSent, ULONG* pulBytesReceived, ULONG* pulPacketsSent, ULONG* pulPacketsReceived, ULONG* pulSpeedbps, ULONG* pulUptime)
  82. {
  83. HRESULT hr = S_OK;
  84. HRASCONN hRasConnection;
  85. hr = m_pNetRasConnection->GetRasConnectionHandle(reinterpret_cast<ULONG_PTR*>(&hRasConnection));
  86. if(SUCCEEDED(hr))
  87. {
  88. RAS_STATS Statistics;
  89. Statistics.dwSize = sizeof(RAS_STATS);
  90. if(0 == RasGetConnectionStatistics(hRasConnection, &Statistics))
  91. {
  92. if(NULL != pulBytesSent)
  93. {
  94. *pulBytesSent = Statistics.dwBytesXmited;
  95. }
  96. if(NULL != pulBytesReceived)
  97. {
  98. *pulBytesReceived = Statistics.dwBytesRcved;
  99. }
  100. if(NULL != pulPacketsSent)
  101. {
  102. *pulPacketsSent = Statistics.dwFramesXmited;
  103. }
  104. if(NULL != pulPacketsReceived)
  105. {
  106. *pulPacketsReceived = Statistics.dwFramesRcved;
  107. }
  108. if(NULL != pulUptime)
  109. {
  110. *pulUptime = Statistics.dwConnectDuration / 1000;
  111. }
  112. if(NULL != pulSpeedbps)
  113. {
  114. *pulSpeedbps = Statistics.dwBps;
  115. }
  116. }
  117. else
  118. {
  119. hr = E_FAIL;
  120. }
  121. // any cleanup here?
  122. }
  123. return hr;
  124. }