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.

142 lines
3.5 KiB

  1. #ifndef _MIPADDRESS_HH
  2. #define _MIPADDRESS_HH
  3. // Copyright (c) Microsoft. All Rights Reserved
  4. //
  5. // THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF Microsoft.
  6. // The copyright notice above does not evidence any
  7. // actual or intendd publication of such source code.
  8. //
  9. // OneLiner : Interface for MIPAddress.
  10. // DevUnit : wlbstest
  11. // Author : Murtaza Hakim
  12. //
  13. // Description:
  14. // ------------
  15. // Provides static methods for checking if ip address is valid or not,
  16. // finding subnet, etc.
  17. // Include Files
  18. #include <vector>
  19. #include <wbemidl.h>
  20. #include <comdef.h>
  21. using namespace std;
  22. // Class Definition
  23. class MIPAddress
  24. {
  25. public:
  26. enum IPClass
  27. {
  28. classA,
  29. classB,
  30. classC,
  31. classD,
  32. classE
  33. };
  34. // Description
  35. // -----------
  36. // Checks if the ip address supplied is valid.
  37. //
  38. // IP address needs to be in dotted decimal
  39. // for eg. 192.31.56.2, 128.1.1.1, 1.1.1.1 etc.
  40. // ip addresses in the form 192.31 are not allowed.
  41. // There must be exactly four parts.
  42. //
  43. //
  44. // Parameters
  45. // ----------
  46. // ipAddrToCheck in : ipAddr to check in dotted dec notation.
  47. //
  48. // Returns
  49. // -------
  50. // true if valid else false.
  51. static
  52. bool
  53. checkIfValid(const _bstr_t& ipAddrToCheck );
  54. // Description
  55. // -----------
  56. // Gets the default subnet mask for ip address. The ip address
  57. // needs to be valid for operation to be successful.
  58. //
  59. // IP address needs to be in dotted decimal
  60. // for eg. 192.31.56.2, 128.1.1.1, 1.1.1.1 etc.
  61. // ip addresses in the form 192.31 are not allowed.
  62. // There must be exactly four parts.
  63. //
  64. // Parameters
  65. // ----------
  66. // ipAddress IN : ip address for which default subnet required.
  67. // subnetMask OUT : default subnet mask for ip.
  68. //
  69. // Returns
  70. // -------
  71. // true if able to find default subnet or false if ipAddress was
  72. // invalid.
  73. static
  74. bool
  75. getDefaultSubnetMask( const _bstr_t& ipAddr,
  76. _bstr_t& subnetMask );
  77. // Description
  78. // -----------
  79. // Gets the class to which this ip address belongs.
  80. // class A: 1 - 126
  81. // class B: 128 - 191
  82. // class C: 192 - 223
  83. // class D: 224 - 239
  84. // class D: 240 - 247
  85. //
  86. // IP address needs to be in dotted decimal
  87. // for eg. 192.31.56.2, 128.1.1.1, 1.1.1.1 etc.
  88. // ip addresses in the form 192.31 are not allowed.
  89. // There must be exactly four parts.
  90. //
  91. // Parameters
  92. // ----------
  93. // ipAddress IN : ip address for which class is to be found.
  94. // ipClass OUT : class to which ip belongs.
  95. //
  96. // Returns
  97. // -------
  98. // true if able to find class or false if not able to find.
  99. //
  100. static
  101. bool
  102. getIPClass( const _bstr_t& ipAddr,
  103. IPClass& ipClass );
  104. static
  105. bool
  106. isValidIPAddressSubnetMaskPair( const _bstr_t& ipAddress,
  107. const _bstr_t& subnetMask );
  108. static
  109. bool
  110. isContiguousSubnetMask( const _bstr_t& subnetMask );
  111. private:
  112. };
  113. //------------------------------------------------------
  114. //
  115. //------------------------------------------------------
  116. // Inline Functions
  117. //------------------------------------------------------
  118. //
  119. //------------------------------------------------------
  120. // Ensure Type Safety
  121. //------------------------------------------------------
  122. typedef class MIPAddress MIPAddress;
  123. //------------------------------------------------------
  124. //
  125. #endif _MIPADDRESS_HH