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.

267 lines
5.4 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. iplist.c
  5. Abstract:
  6. Contains functions to get IP addresses from TCP/IP stack
  7. Contents:
  8. DnsGetIpAddressList
  9. Author:
  10. Glenn A. Curtis (glennc) 05-May-1197
  11. Revision History:
  12. --*/
  13. //
  14. // includes
  15. //
  16. #include "local.h"
  17. #if 0
  18. /*******************************************************************************
  19. *
  20. * DnsGetIpAddressList
  21. *
  22. * Retrieves all active IP addresses from all active adapters on this machine.
  23. * Returns them as an array
  24. *
  25. * EXIT IpAddressList - filled with retrieved IP addresses
  26. * memory freed with FREE_HEAP
  27. *
  28. * RETURNS number of IP addresses retrieved, or 0 if error
  29. *
  30. * ASSUMES 1. an IP address can be represented in a DWORD
  31. *
  32. ******************************************************************************/
  33. DWORD
  34. DnsGetIpAddressList(
  35. OUT PIP_ARRAY * ppIpAddresses
  36. )
  37. {
  38. DWORD RpcStatus = NO_ERROR;
  39. PDNS_IP_ADDR_LIST pIpAddrList = NULL;
  40. DWORD Count;
  41. DWORD iter = 0;
  42. DWORD iter2 = 0;
  43. *ppIpAddresses = NULL;
  44. if ( !g_IsWin9X )
  45. {
  46. ENVAR_DWORD_INFO filterInfo;
  47. // get config including environment variable
  48. Dns_ReadDwordEnvar(
  49. DnsRegFilterClusterIp,
  50. &filterInfo );
  51. RpcTryExcept
  52. {
  53. Count = R_ResolverGetIpAddressList(
  54. NULL,
  55. &pIpAddrList,
  56. filterInfo
  57. );
  58. }
  59. RpcExcept( DNS_RPC_EXCEPTION_FILTER )
  60. {
  61. RpcStatus = RpcExceptionCode();
  62. }
  63. RpcEndExcept
  64. }
  65. else
  66. RpcStatus = RPC_S_SERVER_UNAVAILABLE;
  67. if ( RpcStatus )
  68. {
  69. *ppIpAddresses = Dns_GetLocalIpAddressArray();
  70. if ( *ppIpAddresses )
  71. {
  72. if ( (*ppIpAddresses)->AddrCount == 0 )
  73. {
  74. FREE_HEAP( *ppIpAddresses );
  75. *ppIpAddresses = NULL;
  76. return 0;
  77. }
  78. else
  79. {
  80. return (*ppIpAddresses)->AddrCount;
  81. }
  82. }
  83. else
  84. return 0;
  85. }
  86. if ( Count && pIpAddrList )
  87. {
  88. *ppIpAddresses = DnsCreateIpArray( Count );
  89. if ( *ppIpAddresses == NULL )
  90. {
  91. FREE_HEAP( pIpAddrList );
  92. return 0;
  93. }
  94. for ( iter = 0; iter < pIpAddrList->dwAddressCount; iter++ )
  95. {
  96. if ( Dns_AddIpToIpArray( *ppIpAddresses,
  97. pIpAddrList ->
  98. AddressArray[iter].ipAddress ) )
  99. {
  100. iter2++;
  101. }
  102. }
  103. FREE_HEAP( pIpAddrList );
  104. }
  105. return iter2;
  106. }
  107. DWORD
  108. DnsGetIpAddressInfoList(
  109. OUT PDNS_ADDRESS_INFO * ppAddrInfo
  110. )
  111. {
  112. DWORD RpcStatus = NO_ERROR;
  113. PDNS_IP_ADDR_LIST pIpAddrList = NULL;
  114. DWORD Count;
  115. DWORD iter = 0;
  116. *ppAddrInfo = NULL;
  117. if ( !g_IsWin9X )
  118. {
  119. RpcTryExcept
  120. {
  121. Count = CRrGetIpAddressList( NULL, &pIpAddrList );
  122. }
  123. RpcExcept( DNS_RPC_EXCEPTION_FILTER )
  124. {
  125. RpcStatus = RpcExceptionCode();
  126. }
  127. RpcEndExcept
  128. }
  129. else
  130. RpcStatus = RPC_S_SERVER_UNAVAILABLE;
  131. if ( RpcStatus )
  132. {
  133. DNS_ADDRESS_INFO ipInfoArray[256];
  134. Count = Dns_GetIpAddresses( ipInfoArray, 256 );
  135. if ( Count )
  136. {
  137. *ppAddrInfo = (PDNS_ADDRESS_INFO )
  138. ALLOCATE_HEAP( Count * sizeof( DNS_ADDRESS_INFO ) );
  139. if ( *ppAddrInfo == NULL )
  140. return 0;
  141. for ( iter = 0; iter < Count; iter++ )
  142. {
  143. (*ppAddrInfo)[iter].ipAddress = ipInfoArray[iter].ipAddress;
  144. (*ppAddrInfo)[iter].subnetMask = ipInfoArray[iter].subnetMask;
  145. }
  146. }
  147. return Count;
  148. }
  149. if ( Count && pIpAddrList )
  150. {
  151. *ppAddrInfo = (PDNS_ADDRESS_INFO )
  152. ALLOCATE_HEAP( Count * sizeof( DNS_ADDRESS_INFO ) );
  153. if ( *ppAddrInfo == NULL )
  154. {
  155. FREE_HEAP( pIpAddrList );
  156. return 0;
  157. }
  158. if ( pIpAddrList->dwAddressCount < Count )
  159. {
  160. Count = pIpAddrList->dwAddressCount;
  161. }
  162. for ( iter = 0; iter < Count; iter++ )
  163. {
  164. (*ppAddrInfo)[iter].ipAddress =
  165. pIpAddrList->AddressArray[iter].ipAddress;
  166. (*ppAddrInfo)[iter].subnetMask =
  167. pIpAddrList->AddressArray[iter].subnetMask;
  168. }
  169. FREE_HEAP( pIpAddrList );
  170. }
  171. return Count;
  172. }
  173. #endif
  174. DWORD
  175. DnsGetDnsServerList(
  176. OUT PIP_ARRAY * ppDnsAddresses
  177. )
  178. {
  179. PDNS_NETINFO pNetworkInfo;
  180. PIP_ARRAY pserverIpArray;
  181. if ( ! ppDnsAddresses )
  182. {
  183. return 0;
  184. }
  185. *ppDnsAddresses = NULL;
  186. DNSDBG( TRACE, ( "DnsGetDnsServerList()\n" ));
  187. pNetworkInfo = GetNetworkInfo();
  188. if ( !pNetworkInfo )
  189. {
  190. return 0;
  191. }
  192. pserverIpArray = NetInfo_ConvertToIpArray( pNetworkInfo );
  193. NetInfo_Free( pNetworkInfo );
  194. if ( !pserverIpArray )
  195. {
  196. return 0;
  197. }
  198. // if no servers read, return
  199. if ( pserverIpArray->AddrCount == 0 )
  200. {
  201. FREE_HEAP( pserverIpArray );
  202. return 0;
  203. }
  204. *ppDnsAddresses = pserverIpArray;
  205. return( pserverIpArray->AddrCount );
  206. }