Leaked source code of windows server 2003
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.

199 lines
4.0 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include "precomp.h"
  4. #include "CNATInfoService.h"
  5. #include "pastif.h"
  6. CNATInfoService::CNATInfoService()
  7. {
  8. m_pEventSink = NULL;
  9. m_pHNetConnection = NULL;
  10. }
  11. HRESULT CNATInfoService::FinalConstruct()
  12. {
  13. HRESULT hr = S_OK;
  14. return hr;
  15. }
  16. HRESULT CNATInfoService::FinalRelease()
  17. {
  18. HRESULT hr = S_OK;
  19. if(NULL != m_pHNetConnection)
  20. {
  21. m_pHNetConnection->Release();
  22. }
  23. return hr;
  24. }
  25. HRESULT CNATInfoService::Initialize(IHNetConnection* pHNetConnection)
  26. {
  27. HRESULT hr = S_OK;
  28. m_pHNetConnection = pHNetConnection;
  29. m_pHNetConnection->AddRef();
  30. return hr;
  31. }
  32. HRESULT CNATInfoService::Advise(IUPnPEventSink* pesSubscriber)
  33. {
  34. HRESULT hr = S_OK;
  35. m_pEventSink = pesSubscriber;
  36. m_pEventSink->AddRef();
  37. return hr;
  38. }
  39. HRESULT CNATInfoService::Unadvise(IUPnPEventSink* pesSubscriber)
  40. {
  41. HRESULT hr = S_OK;
  42. m_pEventSink->Release();
  43. m_pEventSink = NULL;
  44. return hr;
  45. }
  46. HRESULT CNATInfoService::get_IPList(BSTR *pIPList)
  47. {
  48. HRESULT hr = S_OK;
  49. *pIPList = SysAllocString(L"");
  50. if(NULL == *pIPList)
  51. {
  52. hr = E_OUTOFMEMORY;
  53. }
  54. return hr;
  55. }
  56. HRESULT CNATInfoService::get_PublicIP(BSTR *pPublicIP)
  57. {
  58. *pPublicIP = NULL;
  59. return E_UNEXPECTED;
  60. }
  61. HRESULT CNATInfoService::get_Port(ULONG* pPort)
  62. {
  63. return E_UNEXPECTED;
  64. }
  65. HRESULT CNATInfoService::get_Protocol(BSTR* pProtocol)
  66. {
  67. *pProtocol = NULL;
  68. return E_UNEXPECTED;
  69. }
  70. HRESULT CNATInfoService::get_PrivateIP(BSTR* pPrivateIP)
  71. {
  72. *pPrivateIP = NULL;
  73. return E_UNEXPECTED;
  74. }
  75. HRESULT CNATInfoService::GetPublicIPList(BSTR* IPListp)
  76. {
  77. HRESULT hr = S_OK;
  78. PPAST_INTERFACE Interfacep = NULL;
  79. PLIST_ENTRY Linkp = NULL;
  80. ULONG AddressCount = 0;
  81. LPOLESTR AddressListp = NULL;
  82. _ASSERT(IPListp != NULL);
  83. SysFreeString(*IPListp);
  84. *IPListp = NULL;
  85. EnterCriticalSection(&PastInterfaceLock);
  86. for(Linkp = PastInterfaceList.Flink;
  87. Linkp != &PastInterfaceList;
  88. Linkp = Linkp->Flink)
  89. {
  90. Interfacep = CONTAINING_RECORD(Linkp, PAST_INTERFACE, Link);
  91. if( NAT_IFC_BOUNDARY(Interfacep->Characteristics) )
  92. {
  93. //
  94. // Check for all IPs on the Boundary Interface(s)
  95. //
  96. for(ULONG i = 0;
  97. (i < Interfacep->BindingCount) &&
  98. (Interfacep->BindingArray[i].Address != INADDR_NONE) ;
  99. i++)
  100. {
  101. if( AddressCount > 0 )
  102. {
  103. AddressListp = AppendAndAllocateWString(AddressListp, L",");
  104. }
  105. AddressListp = AppendAndAllocateWString(AddressListp,
  106. INET_NTOW(Interfacep->BindingArray[i].Address));
  107. AddressCount++;
  108. }
  109. }
  110. }
  111. LeaveCriticalSection(&PastInterfaceLock);
  112. //
  113. // Allocate and construct the BSTR reply
  114. //
  115. if( AddressListp != NULL)
  116. {
  117. *IPListp = SysAllocString( AddressListp );
  118. if( *IPListp != NULL )
  119. {
  120. hr = E_OUTOFMEMORY;
  121. }
  122. }
  123. return hr;
  124. }
  125. HRESULT CNATInfoService::GetPortMappingPrivateIP(
  126. BSTR PublicIP,
  127. ULONG ulPort,
  128. BSTR Protocol,
  129. BSTR* pPrivateIP
  130. )
  131. {
  132. HRESULT hr = E_NOTIMPL;
  133. SysFreeString(*pPrivateIP);
  134. *pPrivateIP = NULL;
  135. return hr;
  136. }
  137. HRESULT CNATInfoService::GetPortMappingPublicIP(BSTR PrivateIP, ULONG ulPort, BSTR Protocol, BSTR* pPublicIP)
  138. {
  139. HRESULT hr = E_NOTIMPL;
  140. SysFreeString(*pPublicIP);
  141. *pPublicIP = NULL;
  142. return hr;
  143. }