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.

410 lines
11 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1998 **/
  4. /**********************************************************************/
  5. /*
  6. ipstats.cpp
  7. IP Statistics implementation.
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "column.h" // containercolumninfo
  12. #include "ipconn.h" // IPConnection
  13. #include "igmprm.h"
  14. #include "rtrlib.h" // DWORD_CMP
  15. #include "ipctrl.h" // INET_CMP
  16. #include "statsdlg.h"
  17. #include "IGMPstat.h"
  18. #include "resource.h"
  19. /*---------------------------------------------------------------------------
  20. IGMPGroupStatistics implementation
  21. ---------------------------------------------------------------------------*/
  22. extern const ContainerColumnInfo s_rgIGMPGroupStatsColumnInfo[];
  23. const ContainerColumnInfo s_rgIGMPGroupStatsColumnInfo[] =
  24. {
  25. { IDS_STATS_IGMPGROUPTBL_INTERFACE, 0, TRUE, COL_IF_NAME },
  26. { IDS_STATS_IGMPGROUPTBL_GROUPADDR, 0, TRUE, COL_IPADDR },,
  27. { IDS_STATS_IGMPGROUPTBL_LASTREPORTER, 0, TRUE, COL_STRING },
  28. { IDS_STATS_IGMPGROUPTBL_EXPIRYTIME, 0, TRUE, COL_DATE },
  29. };
  30. IGMPGroupStatistics::IGMPGroupStatistics()
  31. : IPStatisticsDialog(STATSDLG_FULLWINDOW |
  32. STATSDLG_CONTEXTMENU |
  33. STATSDLG_SELECT_COLUMNS)
  34. {
  35. SetColumnInfo(s_rgIGMPGroupStatsColumnInfo,
  36. DimensionOf(s_rgIGMPGroupStatsColumnInfo));
  37. }
  38. struct IGMPGroupData
  39. {
  40. DWORD IpAddr;
  41. DWORD GrpAddr;
  42. DWORD LastReporter;
  43. DWORD GroupExpiryTime;
  44. };
  45. HRESULT IGMPGroupStatistics::RefreshData(BOOL fGrabNewData)
  46. {
  47. DWORD dwIndex = 0;
  48. HRESULT hr;
  49. LPBYTE pData = NULL;
  50. LPBYTE ptr;
  51. SPBYTE spMibData;
  52. int cRows = 0;
  53. CString st;
  54. ULONG iPos;
  55. int i;
  56. TCHAR szNumber[32];
  57. PIGMP_MIB_GET_OUTPUT_DATA pimgod;
  58. PIGMP_MIB_GROUP_IFS_LIST pGroupIfsList;
  59. PIGMP_MIB_GROUP_INFO pGrpInfo;
  60. IGMPGroupData * pIGMPData;
  61. Assert(m_pIPConn);
  62. pData = NULL;
  63. hr = MibGetIgmp(m_pIPConn->GetMibHandle(),
  64. IGMP_GROUP_IFS_LIST_ID,
  65. dwIndex,
  66. &pData,
  67. QUERYMODE_GETFIRST);
  68. spMibData = pData;
  69. while (hr == hrOK)
  70. {
  71. pimgod=(PIGMP_MIB_GET_OUTPUT_DATA) pData;
  72. ptr=pimgod->Buffer;
  73. //for each imgid.Count number of groups
  74. for (UINT z=0; z < pimgod->Count; z++)
  75. {
  76. Assert(pData);
  77. pGroupIfsList = (PIGMP_MIB_GROUP_IFS_LIST) ptr;
  78. pGrpInfo= (PIGMP_MIB_GROUP_INFO)pGroupIfsList->Buffer;
  79. //iterate interfaces attached to this group
  80. for (UINT y=0; y < pGroupIfsList->NumInterfaces ; y++, pGrpInfo++)
  81. {
  82. // fill in row of group membership statistics (per interface)
  83. pIGMPData = new IGMPGroupData;
  84. pIGMPData->GrpAddr=pGroupIfsList->GroupAddr;
  85. pIGMPData->IpAddr=pGrpInfo->IpAddr;
  86. pIGMPData->LastReporter=pGrpInfo->LastReporter;
  87. pIGMPData->GroupExpiryTime=pGrpInfo->GroupExpiryTime;
  88. m_listCtrl.InsertItem(cRows, _T(""));
  89. m_listCtrl.SetItemData(cRows, reinterpret_cast<DWORD>(pIGMPData));
  90. //for each statistic column
  91. for (i=0; i<MVR_IGMPGROUP_COUNT; i++)
  92. {
  93. if (IsSubitemVisible(i))
  94. {
  95. switch (i)
  96. {
  97. case MVR_IGMPGROUP_INTERFACE:
  98. st = INET_NTOA(pIGMPData->IpAddr);
  99. break;
  100. case MVR_IGMPGROUP_GROUPADDR:
  101. st = INET_NTOA(pIGMPData->GrpAddr);
  102. break;
  103. case MVR_IGMPGROUP_LASTREPORTER:
  104. st = INET_NTOA(pIGMPData->LastReporter);
  105. break;
  106. case MVR_IGMPGROUP_EXPIRYTIME:
  107. FormatNumber( pIGMPData->GroupExpiryTime,szNumber, DimensionOf(szNumber), FALSE);
  108. st = szNumber;
  109. break;
  110. default:
  111. Panic1("Unknown IGMPGroup info id : %d", i);
  112. break;
  113. }
  114. iPos = MapSubitemToColumn(i);
  115. m_listCtrl.SetItemText(cRows, iPos, (LPCTSTR) st);
  116. }
  117. }
  118. cRows++;
  119. }
  120. pData=(PBYTE) pGrpInfo;
  121. }
  122. //Set index to current
  123. dwIndex = pGroupIfsList->GroupAddr;
  124. // Get the next row
  125. pData = NULL;
  126. hr = MibGetIgmp(m_pIPConn->GetMibHandle(),
  127. IGMP_GROUP_IFS_LIST_ID,
  128. dwIndex,
  129. &pData,
  130. QUERYMODE_GETNEXT);
  131. if (hr == hrOK)
  132. {
  133. spMibData.Free();
  134. spMibData = pData;
  135. }
  136. }
  137. return hrOK;
  138. }
  139. BOOL IGMPGroupStatistics::OnInitDialog()
  140. {
  141. CString st;
  142. st.LoadString(IDS_STATS_IGMPGROUPTBL_TITLE);
  143. SetWindowText((LPCTSTR) st);
  144. return IPStatisticsDialog::OnInitDialog();
  145. }
  146. int CALLBACK IGMPGroupStatisticsCompareProc(LPARAM lParam1, LPARAM lParam2,
  147. LPARAM lParamSort)
  148. {
  149. int iReturn = 0;
  150. IGMPGroupData * pIGMPData1 = (IGMPGroupData *) lParam1;
  151. IGMPGroupData * pIGMPData2 = (IGMPGroupData *) lParam2;
  152. switch (lParamSort)
  153. {
  154. case MVR_IGMPGROUP_INTERFACE:
  155. iReturn = INET_CMP(pIGMPData1->IpAddr, pIGMPData2->IpAddr);
  156. break;
  157. case MVR_IGMPGROUP_GROUPADDR:
  158. iReturn = INET_CMP(pIGMPData1->GrpAddr, pIGMPData2->GrpAddr);
  159. break;
  160. case MVR_IGMPGROUP_LASTREPORTER:
  161. iReturn = DWORD_CMP(pIGMPData1->LastReporter,pIGMPData2->LastReporter);
  162. break;
  163. case MVR_IGMPGROUP_EXPIRYTIME:
  164. iReturn = DWORD_CMP(pIGMPData1->GroupExpiryTime,pIGMPData2->GroupExpiryTime);
  165. break;
  166. default:
  167. Panic1("Unknown IGMPGroup info id : %d", lParamSort);
  168. break;
  169. }
  170. return iReturn;
  171. }
  172. int CALLBACK IGMPGroupStatisticsCompareProcMinus(LPARAM lParam1, LPARAM lParam2,
  173. LPARAM lParamSort)
  174. {
  175. return -IGMPGroupStatisticsCompareProc(lParam1, lParam2, lParamSort);
  176. }
  177. PFNLVCOMPARE IGMPGroupStatistics::GetSortFunction()
  178. {
  179. return IGMPGroupStatisticsCompareProc;
  180. }
  181. PFNLVCOMPARE IGMPGroupStatistics::GetInverseSortFunction()
  182. {
  183. return IGMPGroupStatisticsCompareProcMinus;
  184. }
  185. void IGMPGroupStatistics::PreDeleteAllItems()
  186. {
  187. IGMPGroupData * pIGMPData;
  188. for (int i=0; i<m_listCtrl.GetItemCount(); i++)
  189. {
  190. pIGMPData = (IGMPGroupData *) m_listCtrl.GetItemData(i);
  191. delete pIGMPData;
  192. }
  193. }
  194. /*---------------------------------------------------------------------------
  195. IGMPInterfaceStatistics implementation
  196. ---------------------------------------------------------------------------*/
  197. extern const ContainerColumnInfo s_rgIGMPInterfaceStatsColumnInfo[];
  198. const ContainerColumnInfo s_rgIGMPInterfaceStatsColumnInfo[] =
  199. {
  200. { IDS_STATS_IGMPGROUPTBL_GROUPADDR, 0, TRUE, COL_IPADDR },
  201. { IDS_STATS_IGMPGROUPTBL_LASTREPORTER, 0, TRUE, COL_STRING },
  202. { IDS_STATS_IGMPGROUPTBL_EXPIRYTIME, 0, TRUE, COL_DATE },
  203. };
  204. IGMPInterfaceStatistics::IGMPInterfaceStatistics()
  205. : IPStatisticsDialog(STATSDLG_FULLWINDOW |
  206. STATSDLG_CONTEXTMENU |
  207. STATSDLG_SELECT_COLUMNS)
  208. {
  209. SetColumnInfo(s_rgIGMPInterfaceStatsColumnInfo,
  210. DimensionOf(s_rgIGMPInterfaceStatsColumnInfo));
  211. }
  212. struct IGMPInterfaceData
  213. {
  214. DWORD GrpAddr;
  215. DWORD LastReporter;
  216. DWORD GroupExpiryTime;
  217. };
  218. HRESULT IGMPInterfaceStatistics::RefreshData(BOOL fGrabNewData)
  219. {
  220. DWORD dwIndex = 0;
  221. HRESULT hr;
  222. LPBYTE pData = NULL;
  223. SPBYTE spMibData;
  224. int cRows = 0;
  225. CString st;
  226. ULONG iPos;
  227. int i;
  228. LPBYTE ptr;
  229. TCHAR szNumber[32];
  230. PIGMP_MIB_GET_OUTPUT_DATA pimgod;
  231. PIGMP_MIB_IF_GROUPS_LIST pIfGroupList;
  232. PIGMP_MIB_GROUP_INFO pGrpInfo;
  233. DWORD dwQuery = QUERYMODE_GETFIRST;
  234. IGMPInterfaceData * pIGMPData;
  235. Assert(m_pIPConn);
  236. pData = NULL;
  237. hr = MibGetIgmp(m_pIPConn->GetMibHandle(),
  238. IGMP_IF_GROUPS_LIST_ID,
  239. dwIndex,
  240. &pData,
  241. QUERYMODE_GETFIRST);
  242. spMibData = pData;
  243. dwQuery = QUERYMODE_GETNEXT;
  244. pimgod=(PIGMP_MIB_GET_OUTPUT_DATA) pData;
  245. ptr=pimgod->Buffer;
  246. // for each imgid.Count number of groups
  247. for (UINT z=0; z < pimgod->Count; z++)
  248. {
  249. Assert(pData);
  250. pIfGroupList = (PIGMP_MIB_IF_GROUPS_LIST) ptr;
  251. pGrpInfo= (PIGMP_MIB_GROUP_INFO)pIfGroupList->Buffer;
  252. // iterate interfaces attached to this group
  253. for (UINT y=0; y < pIfGroupList->NumGroups ; y++, pGrpInfo++)
  254. {
  255. // fill in row of group membership statistics (per interface)
  256. pIGMPData = new IGMPInterfaceData;
  257. pIGMPData->GrpAddr=pGrpInfo->GroupAddr;
  258. pIGMPData->LastReporter=pGrpInfo->LastReporter;
  259. pIGMPData->GroupExpiryTime=pGrpInfo->GroupExpiryTime;
  260. m_listCtrl.InsertItem(cRows, _T(""));
  261. m_listCtrl.SetItemData(cRows, reinterpret_cast<DWORD>(pIGMPData));
  262. //for each statistic column
  263. for (i=0; i<MVR_IGMPGROUP_COUNT; i++)
  264. {
  265. if (IsSubitemVisible(i))
  266. {
  267. switch (i)
  268. {
  269. case MVR_IGMPINTERFACE_GROUPADDR:
  270. st = INET_NTOA(pIGMPData->GrpAddr);
  271. break;
  272. case MVR_IGMPINTERFACE_LASTREPORTER:
  273. st = INET_NTOA(pIGMPData->LastReporter);
  274. break;
  275. case MVR_IGMPINTERFACE_EXPIRYTIME:
  276. FormatNumber( pIGMPData->GroupExpiryTime,szNumber, DimensionOf(szNumber), FALSE);
  277. st = szNumber;
  278. break;
  279. default:
  280. Panic1("Unknown IGMPGroup info id : %d", i);
  281. break;
  282. }
  283. iPos = MapSubitemToColumn(i);
  284. m_listCtrl.SetItemText(cRows, iPos, (LPCTSTR) st);
  285. }
  286. }
  287. cRows++;
  288. }
  289. pData=(PBYTE) pGrpInfo;
  290. }
  291. return hrOK;
  292. }
  293. BOOL IGMPInterfaceStatistics::OnInitDialog()
  294. {
  295. CString st;
  296. st.LoadString(IDS_STATS_IGMPINTERFACETBL_TITLE);
  297. SetWindowText((LPCTSTR) st);
  298. return IPStatisticsDialog::OnInitDialog();
  299. }
  300. int CALLBACK IGMPInterfaceStatisticsCompareProc(LPARAM lParam1, LPARAM lParam2,
  301. LPARAM lParamSort)
  302. {
  303. int iReturn = 0;
  304. IGMPInterfaceData * pIGMPData1 = (IGMPInterfaceData *) lParam1;
  305. IGMPInterfaceData * pIGMPData2 = (IGMPInterfaceData *) lParam2;
  306. switch (lParamSort)
  307. {
  308. case MVR_IGMPINTERFACE_GROUPADDR:
  309. iReturn = INET_CMP(pIGMPData1->GrpAddr, pIGMPData2->GrpAddr);
  310. break;
  311. case MVR_IGMPINTERFACE_LASTREPORTER:
  312. iReturn = DWORD_CMP(pIGMPData1->LastReporter,pIGMPData2->LastReporter);
  313. break;
  314. case MVR_IGMPINTERFACE_EXPIRYTIME:
  315. iReturn = DWORD_CMP(pIGMPData1->GroupExpiryTime,pIGMPData2->GroupExpiryTime);
  316. break;
  317. default:
  318. Panic1("Unknown IGMPINTERFACE info id : %d", lParamSort);
  319. break;
  320. }
  321. return iReturn;
  322. }
  323. int CALLBACK IGMPInterfaceStatisticsCompareProcMinus(LPARAM lParam1, LPARAM lParam2,
  324. LPARAM lParamSort)
  325. {
  326. return -IGMPInterfaceStatisticsCompareProc(lParam1, lParam2, lParamSort);
  327. }
  328. PFNLVCOMPARE IGMPInterfaceStatistics::GetSortFunction()
  329. {
  330. return IGMPInterfaceStatisticsCompareProc;
  331. }
  332. PFNLVCOMPARE IGMPInterfaceStatistics::GetInverseSortFunction()
  333. {
  334. return IGMPInterfaceStatisticsCompareProcMinus;
  335. }
  336. void IGMPInterfaceStatistics::PreDeleteAllItems()
  337. {
  338. IGMPInterfaceData * pIGMPData;
  339. for (int i=0; i<m_listCtrl.GetItemCount(); i++)
  340. {
  341. pIGMPData = (IGMPInterfaceData *) m_listCtrl.GetItemData(i);
  342. delete pIGMPData;
  343. }
  344. }