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.

176 lines
4.1 KiB

  1. // Copyright (c) 2001 Microsoft Corporation
  2. //
  3. // File: NetworkInterface.h
  4. //
  5. // Synopsis: Declares a NetworkInterface
  6. // This object has the knowledge of an
  7. // IP enabled network connection including
  8. // IP address, DHCP information, etc.
  9. //
  10. // History: 03/01/2001 JeffJon Created
  11. #ifndef __CYS_NETWORKINTERFACE_H
  12. #define __CYS_NETWORKINTERFACE_H
  13. #define CYS_DEFAULT_IPADDRESS static_cast<DWORD>(MAKEIPADDRESS(192,168,0,1))
  14. #define CYS_DEFAULT_IPADDRESS_STRING L"192.168.0.1"
  15. #define CYS_DEFAULT_SUBNETMASK static_cast<DWORD>(MAKEIPADDRESS(255,255,255,0))
  16. #define CYS_DEFAULT_SUBNETMASK_STRING L"255.255.255.0"
  17. class NetworkInterface
  18. {
  19. public:
  20. // Constructor
  21. NetworkInterface();
  22. // Desctructor
  23. ~NetworkInterface();
  24. // Initializer
  25. HRESULT
  26. Initialize(const IP_ADAPTER_INFO& adapterInfo);
  27. // Pulic accessor methods
  28. DWORD
  29. GetIPAddress(DWORD addressIndex) const;
  30. DWORD
  31. GetIPAddressCount() const { return static_cast<DWORD>(ipaddresses.size()); }
  32. DWORD
  33. GetSubnetMask(DWORD addressIndex) const;
  34. bool
  35. IsDHCPEnabled() const { return dhcpEnabled; }
  36. bool
  37. DoesAtLeastOneNicFailDHCPLease();
  38. String
  39. GetName() const;
  40. // Converts the name member into a GUID.
  41. HRESULT
  42. GetNameAsGUID(GUID& guid) const;
  43. String
  44. GetFriendlyName(
  45. const String defaultName) const;
  46. String
  47. GetDescription() const;
  48. UINT
  49. GetType() const;
  50. DWORD
  51. GetIndex() const;
  52. String
  53. GetStringIPAddress(DWORD addressIndex) const;
  54. String
  55. GetStringSubnetMask(DWORD addressIndex) const;
  56. void
  57. SetIPAddress(DWORD address, String addressString);
  58. void
  59. SetSubnetMask(DWORD mask, String maskString);
  60. String
  61. GetDNSServerString(DWORD index);
  62. void
  63. GetDNSServers(IPAddressList& servers);
  64. bool
  65. IsDHCPAvailable() const;
  66. bool
  67. CanDetectDHCPServer();
  68. bool
  69. IsConnected() const;
  70. bool
  71. IsModem() const;
  72. // Uses IsIPAddressInUse to see if the IP address is in use
  73. // on the network. If it is, the IP address is incremented and tried
  74. // again. The returned IP address is the next available IP address on
  75. // the network or the startAddress if all are detected.
  76. DWORD
  77. GetNextAvailableIPAddress(
  78. DWORD startAddress,
  79. DWORD subnetMask);
  80. // Uses SendARP to see if the available IP is in use on the network using
  81. // the IP address of the interface as the src.
  82. bool
  83. IsIPAddressInUse(
  84. DWORD ipaddress,
  85. DWORD subnetMask);
  86. private:
  87. // Adds a route to the TCP/IP table so that we can send packets for
  88. // the specified IP address to the interface reguardless of whether
  89. // or not the IP address is on the same subnet as the interface's IP
  90. void
  91. SetRoute(
  92. DWORD ipaddress,
  93. DWORD subnetMask);
  94. // Removes a route in the TCP/IP table that was set with SetRoute
  95. void
  96. RemoveRoute(
  97. DWORD ipaddress,
  98. DWORD subnetMask);
  99. HRESULT
  100. RetrieveAdapterInfoFromRegistry();
  101. HRESULT
  102. SetIPList(const IP_ADDR_STRING& ipList);
  103. bool
  104. IsStandardAdapterConnected(const GUID& guid) const;
  105. bool initialized;
  106. String name;
  107. String description;
  108. UINT type;
  109. DWORD index;
  110. bool dhcpEnabled;
  111. bool dhcpServerAvailable;
  112. StringVector ipaddressStringList;
  113. StringVector subnetMaskStringList;
  114. StringVector dnsServerSearchOrder;
  115. IPAddressList ipaddresses;
  116. IPAddressList subnetMasks;
  117. // Copy constructor and assignment operator not allowed
  118. NetworkInterface(const NetworkInterface& nic);
  119. NetworkInterface& operator=(const NetworkInterface& rhs);
  120. };
  121. #endif // __CYS_NETWORKINTERFACE_H