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.

151 lines
3.7 KiB

  1. //##--------------------------------------------------------------
  2. //
  3. // File: portscoll.cpp
  4. //
  5. // Synopsis: Implementation of CPortsCollection class responsible
  6. // for holding a collection of ports in a multi_map
  7. //
  8. // History: 10/22/98 MKarki Created
  9. //
  10. // Copyright (C) 1997-98 Microsoft Corporation
  11. // All rights reserved.
  12. //
  13. //----------------------------------------------------------------
  14. #include "radcommon.h"
  15. #include "portscoll.h"
  16. //++--------------------------------------------------------------
  17. //
  18. // Function: Insert
  19. //
  20. // Synopsis: This is CPortsCollection class public method which
  21. // is called to insert a port,address pair into the
  22. // collection
  23. //
  24. // Arguments: [in] DWORD - port
  25. // [in] DWORD - IP Address
  26. //
  27. // Returns: HRESULT
  28. //
  29. // History: MKarki Created 10/22/97
  30. //
  31. //----------------------------------------------------------------
  32. HRESULT CPortsCollection::Insert (
  33. /*[in]*/ WORD wPort,
  34. /*[in]*/ DWORD dwIPAddress
  35. )
  36. {
  37. bool bInsert = true;
  38. //
  39. // check for this port already in map
  40. //
  41. pair <PORTITR, PORTITR>
  42. itrPair = m_mapPorts.equal_range (wPort);
  43. if (itrPair.first != itrPair.second)
  44. {
  45. //
  46. // we already have values with this key in the collection
  47. //
  48. PORTITR itr = itrPair.first;
  49. do
  50. {
  51. if (INADDR_ANY == dwIPAddress)
  52. {
  53. itr = m_mapPorts.erase (itr);
  54. }
  55. else
  56. {
  57. if (INADDR_ANY == (*itr).second)
  58. {
  59. bInsert = false;
  60. }
  61. ++itr;
  62. }
  63. }
  64. while (itr != itrPair.second);
  65. }
  66. //
  67. // insert this port,address pair if required
  68. //
  69. if (bInsert)
  70. {
  71. m_mapPorts.insert (
  72. PORTSCOLLECTION::value_type (wPort, dwIPAddress)
  73. );
  74. }
  75. return (S_OK);
  76. } // end of CPortsCollection::Insert method
  77. //++--------------------------------------------------------------
  78. //
  79. // Function: GetNext
  80. //
  81. // Synopsis: This is CPortsCollection class public method which
  82. // is called to get the next element from the map
  83. //
  84. // Arguments: [out] PWORD - port
  85. // [out] PDWORD - IP Address
  86. //
  87. // Returns: HRESULT
  88. //
  89. // History: MKarki Created 10/22/97
  90. //
  91. //----------------------------------------------------------------
  92. HRESULT CPortsCollection::GetNext (
  93. /*[out]*/ PWORD pwPort,
  94. /*[out]*/ PDWORD pdwIPAddress
  95. )
  96. {
  97. HRESULT hr = S_OK;
  98. _ASSERT (pwPort && pdwIPAddress);
  99. if (false == m_bDoneGet)
  100. {
  101. m_itr = m_mapPorts.begin();
  102. m_bDoneGet = true;
  103. }
  104. if (m_itr != m_mapPorts.end ())
  105. {
  106. *pwPort = (*m_itr).first;
  107. *pdwIPAddress =(*m_itr).second;
  108. ++m_itr;
  109. }
  110. else
  111. {
  112. hr = E_FAIL;
  113. }
  114. return (hr);
  115. } // end of CPortsCollection::GetNext method
  116. //++--------------------------------------------------------------
  117. //
  118. // Function: ~CPortsCollection
  119. //
  120. // Synopsis: This is CPortsCollection class public destruction
  121. //
  122. // Arguments: none
  123. //
  124. // Returns: none
  125. //
  126. // History: MKarki Created 10/22/97
  127. //
  128. //----------------------------------------------------------------
  129. CPortsCollection::~CPortsCollection ()
  130. {
  131. PORTITR itr = m_mapPorts.begin ();
  132. while (itr != m_mapPorts.end ())
  133. {
  134. itr = m_mapPorts.erase (itr);
  135. }
  136. } // end of CPortsCollection::~CPortsCollection method