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.

162 lines
4.1 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-1999 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // AdmNetUtils.cpp
  7. //
  8. // Abstract:
  9. // Implementation of network utility functions.
  10. //
  11. // Author:
  12. // David Potter (davidp) February 19, 1998
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include <wtypes.h>
  20. #include "clusrtl.h"
  21. #include "AdmNetUtils.h"
  22. /////////////////////////////////////////////////////////////////////////////
  23. //++
  24. //
  25. // BIsValidIpAddress
  26. //
  27. // Routine Description:
  28. // Determine if the specified string is a valid IP address.
  29. //
  30. // Arguments:
  31. // pszAddress [IN] Address string to validate.
  32. //
  33. // Return Value:
  34. // TRUE String is valid IP address.
  35. // FALSE String is not a valid IP address.
  36. //
  37. //--
  38. /////////////////////////////////////////////////////////////////////////////
  39. BOOL BIsValidIpAddress( IN LPCWSTR pszAddress )
  40. {
  41. ULONG nAddress;
  42. DWORD nStatus;
  43. BOOL bIsValid = FALSE;
  44. nStatus = ClRtlTcpipStringToAddress( pszAddress, &nAddress );
  45. if ( nStatus == ERROR_SUCCESS )
  46. {
  47. bIsValid = ClRtlIsValidTcpipAddress( nAddress );
  48. } // if: converted address successfully
  49. return bIsValid;
  50. } //*** BIsValidIpAddress()
  51. /////////////////////////////////////////////////////////////////////////////
  52. //++
  53. //
  54. // BIsValidSubnetMask
  55. //
  56. // Routine Description:
  57. // Determine if the specified string is a valid IP subnet mask.
  58. //
  59. // Arguments:
  60. // pszMask [IN] Subnet mask string to validate.
  61. //
  62. // Return Value:
  63. // TRUE String is a valid subnet mask.
  64. // FALSE String is not a valid subnet mask.
  65. //
  66. //--
  67. /////////////////////////////////////////////////////////////////////////////
  68. BOOL BIsValidSubnetMask( IN LPCWSTR pszMask )
  69. {
  70. ULONG nMask;
  71. DWORD nStatus;
  72. BOOL bIsValid = FALSE;
  73. nStatus = ClRtlTcpipStringToAddress( pszMask, &nMask );
  74. if ( nStatus == ERROR_SUCCESS )
  75. {
  76. bIsValid = ClRtlIsValidTcpipSubnetMask( nMask );
  77. } // if: converted mask successfully
  78. return bIsValid;
  79. } //*** BIsValidSubnetMask()
  80. /////////////////////////////////////////////////////////////////////////////
  81. //++
  82. //
  83. // BIsValidIpAddressAndSubnetMask
  84. //
  85. // Routine Description:
  86. // Determine if the specified IP address and subnet mask strings are
  87. // valid when used together.
  88. //
  89. // Arguments:
  90. // pszAddress [IN] Address string to validate.
  91. // pszMask [IN] Subnet mask string to validate.
  92. //
  93. // Return Value:
  94. // TRUE Address and mask are valid together.
  95. // FALSE Address and mask are not valid when used together.
  96. //
  97. //--
  98. /////////////////////////////////////////////////////////////////////////////
  99. BOOL BIsValidIpAddressAndSubnetMask( IN LPCWSTR pszAddress, IN LPCWSTR pszMask )
  100. {
  101. ULONG nAddress;
  102. ULONG nMask;
  103. DWORD nStatus;
  104. BOOL bIsValid = FALSE;
  105. nStatus = ClRtlTcpipStringToAddress( pszAddress, &nAddress );
  106. if ( nStatus == ERROR_SUCCESS )
  107. {
  108. nStatus = ClRtlTcpipStringToAddress( pszMask, &nMask );
  109. if ( nStatus == ERROR_SUCCESS )
  110. {
  111. bIsValid = ClRtlIsValidTcpipAddressAndSubnetMask( nAddress, nMask );
  112. } // if: converted mask successfully
  113. } // if: converted address successfully
  114. return bIsValid;
  115. } //*** BIsValidIpAddressAndSubnetMask()
  116. /////////////////////////////////////////////////////////////////////////////
  117. //++
  118. //
  119. // BIsIpAddressInUse
  120. //
  121. // Routine Description:
  122. // Determine if the specified IP address is already in use (exists
  123. // on the network).
  124. //
  125. // Arguments:
  126. // pszAddress [IN] Address string to check.
  127. //
  128. // Return Value:
  129. // TRUE Address is already in use.
  130. // FALSE Address is available.
  131. //
  132. //--
  133. /////////////////////////////////////////////////////////////////////////////
  134. BOOL BIsIpAddressInUse( IN LPCWSTR pszAddress )
  135. {
  136. ULONG nAddress;
  137. DWORD nStatus;
  138. BOOL bIsInUse = FALSE;
  139. nStatus = ClRtlTcpipStringToAddress( pszAddress, &nAddress );
  140. if ( nStatus == ERROR_SUCCESS )
  141. {
  142. bIsInUse = ClRtlIsDuplicateTcpipAddress( nAddress );
  143. } // if: converted address successfully
  144. return bIsInUse;
  145. } //*** BIsIpAddressInUse()