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.

234 lines
5.3 KiB

  1. #include "stdafx.h"
  2. #include "MyAdapterNotify.h"
  3. /////////////////////////////////////////////////////////////////////////////
  4. // CMyAdapterNotify
  5. //
  6. IcqPrx * g_IcqPrxp = NULL;
  7. ULONG g_MyPublicIp = 0L;
  8. ULONG g_MyPrivateIp = 0L;
  9. //
  10. // This function will be call when a new adapter is made active
  11. //
  12. STDMETHODIMP
  13. CMyAdapterNotify::AdapterAdded(
  14. IAdapterInfo* pAdapter
  15. )
  16. {
  17. ULONG AdapterIndex = 0;
  18. ALG_ADAPTER_TYPE AdapterType ;
  19. ULONG AddressCount = 0;
  20. PULONG AddressArrayp = NULL;
  21. HRESULT Result = S_OK;
  22. ICQ_TRC(TM_IF, TL_TRACE, ("CMyAdapterNotify::AdapterAdded"));
  23. return S_OK;
  24. }
  25. //
  26. // This function will be call when a adapter is remove and/or disable
  27. //
  28. STDMETHODIMP
  29. CMyAdapterNotify::AdapterRemoved(
  30. IAdapterInfo* pAdapter
  31. )
  32. {
  33. ULONG AdapterIndex = 0;
  34. ALG_ADAPTER_TYPE AdapterType ;
  35. ULONG AddressCount = 0;
  36. PULONG AddressArrayp = NULL;
  37. HRESULT Result = S_OK;
  38. ICQ_TRC(TM_IF, TL_TRACE, ("CMyAdapterNotify::AdapterRemoved"));
  39. Result = pAdapter->GetAdapterIndex(&AdapterIndex);
  40. if ( FAILED(Result) )
  41. {
  42. ICQ_TRC(TM_IF, TL_ERROR, ("AdapterIndex has failed"));
  43. return S_FALSE;
  44. }
  45. Result = pAdapter->GetAdapterType(&AdapterType);
  46. if ( FAILED(Result) )
  47. {
  48. ICQ_TRC(TM_IF, TL_ERROR, ("Adapter Type has failed"));
  49. return S_FALSE;
  50. }
  51. Result = pAdapter->GetAdapterAddresses(&AddressCount,
  52. &AddressArrayp);
  53. if ( FAILED(Result) )
  54. {
  55. ICQ_TRC(TM_IF, TL_ERROR, ("Adapter Addresses has failed"));
  56. return S_FALSE;
  57. }
  58. //
  59. // Create a report on the gathered information
  60. //
  61. ICQ_TRC(TM_IF, TL_TRACE,
  62. (" Interface FW %u: BD %u: PV %u ",
  63. ALG_IFC_FW(AdapterType),
  64. ALG_IFC_BOUNDARY(AdapterType),
  65. ALG_IFC_PRIVATE(AdapterType))
  66. );
  67. ICQ_TRC(TM_IF, TL_TRACE,
  68. ("Interface index: %u addr count %u",
  69. AdapterIndex, AddressCount));
  70. for(ULONG i = 0; i < AddressCount; i++)
  71. {
  72. ICQ_TRC(TM_IF, TL_TRACE,
  73. ("Adapter Address[%u] is %s",
  74. i,
  75. INET_NTOA(AddressArrayp[i]))
  76. );
  77. }
  78. //
  79. // Remove ICQ PROXY HERE
  80. //
  81. if( (ALG_IFC_FW(AdapterType) ||
  82. ALG_IFC_BOUNDARY(AdapterType)) )
  83. {
  84. ASSERT( g_IcqPrxp != NULL );
  85. STOP_COMPONENT( g_IcqPrxp );
  86. DEREF_COMPONENT( g_IcqPrxp, eRefInitialization );
  87. }
  88. else
  89. {
  90. g_MyPrivateIp = 0;
  91. }
  92. return S_OK;
  93. }
  94. //
  95. // This function will be call when a adapter is modified
  96. //
  97. STDMETHODIMP
  98. CMyAdapterNotify::AdapterModified(
  99. IAdapterInfo* pAdapter
  100. )
  101. {
  102. ULONG AdapterIndex = 0;
  103. ALG_ADAPTER_TYPE AdapterType ;
  104. ULONG AddressCount = 0;
  105. PULONG AddressArrayp = NULL;
  106. HRESULT Result = S_OK;
  107. ICQ_TRC(TM_IF, TL_TRACE, ("CMyAdapterNotify::AdapterModified"));
  108. Result = pAdapter->GetAdapterIndex(&AdapterIndex);
  109. if ( FAILED(Result) )
  110. {
  111. ICQ_TRC(TM_IF, TL_ERROR, ("AdapterIndex has failed"));
  112. return S_FALSE;
  113. }
  114. Result = pAdapter->GetAdapterType(&AdapterType);
  115. if ( FAILED(Result) )
  116. {
  117. ICQ_TRC(TM_IF, TL_ERROR, ("Adapter Type has failed"));
  118. return S_FALSE;
  119. }
  120. Result = pAdapter->GetAdapterAddresses(&AddressCount,
  121. &AddressArrayp);
  122. if ( FAILED(Result) )
  123. {
  124. ICQ_TRC(TM_IF, TL_ERROR, ("Adapter Addresses has failed"));
  125. return S_FALSE;
  126. }
  127. //
  128. // Create a report on the gathered information
  129. //
  130. ICQ_TRC(TM_IF, TL_TRACE,
  131. (" Interface FW %u: BD %u: PV %u ",
  132. ALG_IFC_FW(AdapterType),
  133. ALG_IFC_BOUNDARY(AdapterType),
  134. ALG_IFC_PRIVATE(AdapterType))
  135. );
  136. ICQ_TRC(TM_IF, TL_TRACE,
  137. ("Interface index: %u addr count %u",
  138. AdapterIndex, AddressCount));
  139. for(ULONG i = 0; i < AddressCount; i++)
  140. {
  141. ICQ_TRC(TM_IF, TL_TRACE,
  142. ("Adapter Address[%u] is %s",
  143. i,
  144. INET_NTOA(AddressArrayp[i]))
  145. );
  146. }
  147. //
  148. // Initialize the ICQ Proxy here with the appropriate IP
  149. //
  150. if( (ALG_IFC_FW(AdapterType) || ALG_IFC_BOUNDARY(AdapterType)) &&
  151. (AddressCount > 0) &&
  152. (AddressArrayp != NULL)
  153. )
  154. {
  155. ASSERT( g_IcqPrxp is NULL );
  156. NEW_OBJECT( g_IcqPrxp, IcqPrx );
  157. if(g_IcqPrxp is NULL)
  158. {
  159. ASSERT(FALSE);
  160. }
  161. else
  162. {
  163. //
  164. // Use the first IP on the List of IPs belonging to this
  165. // Interface
  166. //
  167. Result = g_IcqPrxp->RunIcq99Proxy(AddressArrayp[0]);
  168. if(Result)
  169. {
  170. ICQ_TRC(TM_IF, TL_ERROR, ("** !! ICQ PRX RUN FAILED !! **"));
  171. }
  172. }
  173. }
  174. else if( (AddressCount > 0) && (AddressArrayp != NULL) )
  175. {
  176. ICQ_TRC(TM_IF, TL_ERROR, ("** !! ICQ PRX WONT RUN !! **"));
  177. g_MyPrivateIp = AddressArrayp[0];
  178. }
  179. return S_OK;
  180. }