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.

238 lines
4.2 KiB

  1. #ifndef _NICCARD_H
  2. #define _NICCARD_H
  3. //
  4. // Copyright (c) Microsoft. All Rights Reserved
  5. //
  6. // THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF Microsoft.
  7. // The copyright notice above does not evidence any
  8. // actual or intended publication of such source code.
  9. //
  10. // OneLiner : NICCard interface.
  11. // DevUnit : wlbstest
  12. // Author : Murtaza Hakim
  13. //
  14. // History:
  15. // --------
  16. //
  17. // Revised by : mhakim
  18. // Date : 02-16-01
  19. // Reason : Added code to find friendly name of nic.
  20. // Description:
  21. // -----------
  22. // Include Files
  23. #include <string>
  24. #include <netcfgx.h>
  25. #include <netcfgn.h>
  26. #include <vector>
  27. using namespace std;
  28. class NICCard
  29. {
  30. public:
  31. enum NICCard_Error
  32. {
  33. NICCard_SUCCESS = 0,
  34. COM_FAILURE = 1,
  35. BOUND = 4,
  36. UNBOUND = 5,
  37. NO_SUCH_NIC = 6,
  38. NO_SUCH_COMPONENT= 7,
  39. };
  40. enum IdentifierType
  41. {
  42. macAddress = 1, // use mac address
  43. guid = 2, // use guid
  44. fullName = 3, // use descriptive name
  45. };
  46. class Info
  47. {
  48. public:
  49. wstring fullName; // nic full name.
  50. wstring guid; // nic guid.
  51. // Edited (mhakim 02-16-01) nic friendly name support.
  52. wstring friendlyName; // nic friendly name.
  53. };
  54. //
  55. // Description:
  56. // -----------
  57. // constructor.
  58. //
  59. // Parameters:
  60. // ----------
  61. // type IN : identifies what type it is whether guid, descriptive name, mac address.
  62. // id IN : wstring representation of guid, descriptive name, mac address.
  63. //
  64. // Returns:
  65. // -------
  66. // none.
  67. NICCard( IdentifierType type,
  68. wstring id);
  69. //
  70. // Description:
  71. // -----------
  72. // destructor.
  73. //
  74. // Parameters:
  75. // ----------
  76. // none
  77. //
  78. // Returns:
  79. // -------
  80. // none.
  81. ~NICCard();
  82. //
  83. // Description:
  84. // -----------
  85. // Checks if the nic card is bound to the service, or protocol.
  86. //
  87. // Parameters:
  88. // ----------
  89. // component IN : the component( protocol or service ) to check.
  90. //
  91. // Returns:
  92. // -------
  93. // BOUND if bound, UNBOUND if not bound else error code.
  94. NICCard_Error
  95. isBoundTo( wstring component );
  96. //
  97. // Description:
  98. // -----------
  99. // Binds the nic card to the service, or protocol.
  100. //
  101. // Parameters:
  102. // ----------
  103. // component IN : the component( protocol or service ) to bind.
  104. //
  105. // Returns:
  106. // -------
  107. // 0 : success else error code.
  108. NICCard_Error
  109. bind( wstring component );
  110. //
  111. // Description:
  112. // -----------
  113. // unbinds the nic card from the service, or protocol.
  114. //
  115. // Parameters:
  116. // ----------
  117. // component IN : the component( protocol or service ) to unbind.
  118. //
  119. // Returns:
  120. // -------
  121. // 0 : success else error code.
  122. NICCard_Error
  123. unbind( wstring component );
  124. //
  125. // Description:
  126. // -----------
  127. // checks if the netcfg lock is available.
  128. //
  129. // Parameters:
  130. // ----------
  131. // none
  132. //
  133. // Returns:
  134. // -------
  135. // 0 : success else error code.
  136. NICCard_Error
  137. isNetCfgAvailable();
  138. //
  139. // Description:
  140. // -----------
  141. // finds all nics on the machine.
  142. //
  143. // Parameters:
  144. // ----------
  145. // nicList IN : vector container to store all nics found.
  146. //
  147. // Returns:
  148. // -------
  149. // 0 : success else error code.
  150. static
  151. NICCard_Error
  152. getNics( vector<NICCard::Info>* nicList );
  153. private:
  154. enum
  155. {
  156. TIME_TO_WAIT = 5,
  157. };
  158. INetCfgComponent *pnccNic;
  159. INetCfg *pnc;
  160. IdentifierType nameType;
  161. wstring nicName;
  162. NICCard_Error status;
  163. NICCard::NICCard_Error
  164. findNIC( IdentifierType type,
  165. wstring nicName,
  166. INetCfgComponent** ppnccNic );
  167. NICCard::NICCard_Error
  168. toggleState( wstring component );
  169. static
  170. int
  171. GetFriendlyNICName(const wstring& guid, wstring& name );
  172. };
  173. //
  174. // Ensure type safety
  175. typedef class NICCard NICCard;
  176. #endif