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.

163 lines
3.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996.
  5. //
  6. // File: mach.hxx
  7. //
  8. // Contents:
  9. // Net helper functions.
  10. //
  11. // History:
  12. //--------------------------------------------------------------------------
  13. #ifndef __MACH_HXX__
  14. #define __MACH_HXX__
  15. #include <rpc.h>
  16. #include <netevent.h>
  17. #include <winsock.h>
  18. typedef struct
  19. {
  20. DWORD Count;
  21. DWORD StringBufferSpace;
  22. WCHAR **NetworkAddresses;
  23. } NetworkAddressVector;
  24. //
  25. // This class is basically just a ref-counted wrapper around
  26. // the NetworkAddressVector struct above.
  27. //
  28. class CIPAddrs
  29. {
  30. public:
  31. CIPAddrs();
  32. ~CIPAddrs();
  33. void IncRefCount();
  34. void DecRefCount();
  35. // These members are read-only by users:
  36. NetworkAddressVector* _pIPAddresses;
  37. private:
  38. LONG _lRefs;
  39. };
  40. class CMachineName
  41. {
  42. public:
  43. CMachineName();
  44. ~CMachineName();
  45. BOOL Initialize();
  46. WCHAR* NetBiosName();
  47. WCHAR* DNSName();
  48. BOOL Compare( IN WCHAR * pwszName );
  49. void IPAddrsChanged(int addrfamily);
  50. CIPAddrs *GetIPAddrs();
  51. private:
  52. typedef BOOL (*PFNISGLOBALADDRESS)(LPSOCKADDR psockaddr);
  53. typedef struct _ADDRESS_QUERY_DATA
  54. {
  55. DWORD dwSig; // see ADDRQUERYDATA_SIG below
  56. int addrfamily;
  57. SOCKET socket;
  58. SOCKET_ADDRESS_LIST* pSockAddrList;
  59. DWORD dwSockAddrListBufferSize;
  60. DWORD dwTotalTimesQueried;
  61. DWORD dwAddrVectorSize;
  62. NetworkAddressVector* pAddresses;
  63. DWORD dwLocalAddrVectorSize;
  64. NetworkAddressVector* pLocalOnlyAddresses;
  65. PFNISGLOBALADDRESS pfnIsGlobalAddress;
  66. DWORD dwMaxAddrStringBufSize;
  67. } ADDRESS_QUERY_DATA;
  68. //
  69. // Private member data
  70. //
  71. CIPAddrs* _pIPAddresses;
  72. WCHAR* _pwszNetBiosName;
  73. WCHAR* _pwszDNSName;
  74. // Used for tracking address changes:
  75. BOOL _bIPV4AddrsChanged;
  76. BOOL _bIPV6AddrsChanged;
  77. // Miscellaneous:
  78. BOOL _bInitialized; // True after we've successfully initialized
  79. // Variables used for querying IPV4 addresses:
  80. ADDRESS_QUERY_DATA _aqdIPV4;
  81. // Variables used for querying IPV6 addresses:
  82. ADDRESS_QUERY_DATA _aqdIPV6;
  83. // lock:
  84. CRITICAL_SECTION _csMachineNameLock;
  85. //
  86. // Private member functions
  87. //
  88. void
  89. SetNetBIOSName();
  90. void
  91. SetDNSName();
  92. void
  93. SetComputerNameHelper(
  94. COMPUTER_NAME_FORMAT format,
  95. WCHAR** ppwszName
  96. );
  97. BOOL
  98. CompareHardCodedLocalHostNames(WCHAR* pwszName);
  99. BOOL
  100. CompareDynamicLocalHostNames(WCHAR* pwszName);
  101. CIPAddrs*
  102. QueryAddresses();
  103. CIPAddrs*
  104. MergeAddresses();
  105. BOOL
  106. QueryAddressesSpecific(ADDRESS_QUERY_DATA* paqd);
  107. BOOL
  108. BuildVector(ADDRESS_QUERY_DATA* paqd, BOOL fLocalOnly);
  109. static BOOL
  110. IsIPV4AddressGlobal(LPSOCKADDR psockaddr);
  111. static BOOL
  112. IsIPV6AddressGlobal(LPSOCKADDR psockaddr);
  113. void InitAQD(
  114. ADDRESS_QUERY_DATA* paqd,
  115. int addrfamily);
  116. void
  117. CopySrcVectorToTargetVector (
  118. NetworkAddressVector* pTargetVector, // The vector to copy into
  119. NetworkAddressVector* pSourceVector, // The vector to copy from
  120. DWORD * pdwCurrentAddress, // On input, the index in the vector to start copying into.
  121. WCHAR** ppszCurrentAddress); // On input, the buffer position to start copying into.
  122. void
  123. ValidateVector(NetworkAddressVector* pVector);
  124. };
  125. const DWORD ADDRQUERYDATA_SIG = 0xFEDCBA04;
  126. extern CMachineName * gpMachineName;
  127. #endif \\__MACH_HXX__