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.

484 lines
10 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. ipconfig.hxx
  5. Abstract:
  6. CIpconfig class definition
  7. Author:
  8. Richard L Firth (rfirth) 29-Oct-1996
  9. Environment:
  10. Win32 user-mode DLL
  11. Revision History:
  12. 29-Oct-1996 rfirth
  13. Created
  14. 15-Jul-1998 arthurbi
  15. Resurrected from the dead
  16. --*/
  17. #ifndef IPCONFIG_H_
  18. #define IPCONFIG_H_
  19. //
  20. // manifests
  21. //
  22. #define HOST_INADDR_ANY 0x00000000
  23. #define HOST_INADDR_NONE 0xffffffff
  24. #define HOST_INADDR_LOOPBACK 0x0100007f
  25. #define KEY_TCP 1
  26. #define KEY_NBT 2
  27. //#define MAX_ADAPTER_NAME_LENGTH 128 // arb.
  28. #define MAX_ADAPTER_ADDRESS_LENGTH 8 // arb.
  29. //
  30. // macros
  31. //
  32. #define IS_VALID_NON_LOOPBACK_IP_ADDRESS(address) \
  33. (((address) != HOST_INADDR_ANY) \
  34. && ((address) != HOST_INADDR_NONE) \
  35. && ((address) != HOST_INADDR_LOOPBACK))
  36. //
  37. // class definitions
  38. //
  39. //
  40. // CIpAddress - IP address and associated subnet mask
  41. //
  42. class CIpAddress {
  43. friend class CAdapterInfo;
  44. friend class CIpAddressList;
  45. private:
  46. CIpAddress * m_Next;
  47. BOOL m_bFound;
  48. DWORD m_dwIpAddress;
  49. DWORD m_dwIpMask;
  50. DWORD m_dwContext;
  51. public:
  52. CIpAddress(
  53. IN DWORD dwIpAddress = INADDR_ANY,
  54. IN DWORD dwIpMask = INADDR_ANY,
  55. IN DWORD dwContext = 0
  56. ) {
  57. m_Next = NULL;
  58. m_bFound = TRUE;
  59. m_dwIpAddress = dwIpAddress;
  60. m_dwIpMask = dwIpMask;
  61. m_dwContext = dwContext;
  62. }
  63. ~CIpAddress() {
  64. /* NOTHING */
  65. }
  66. VOID SetFound(BOOL bFound) {
  67. m_bFound = bFound;
  68. }
  69. BOOL
  70. GetAddress(
  71. OUT LPBYTE lpbAddress,
  72. IN OUT LPDWORD lpdwAddressLength
  73. );
  74. BOOL IsFound(VOID) const {
  75. return m_bFound;
  76. }
  77. DWORD IpAddress(VOID) const {
  78. return m_dwIpAddress;
  79. }
  80. DWORD IpMask(VOID) const {
  81. return m_dwIpMask;
  82. }
  83. DWORD Context(VOID) const {
  84. return m_dwContext;
  85. }
  86. };
  87. //
  88. // CIpAddressList - singly-linked list of IP addresses
  89. //
  90. class CIpAddressList {
  91. friend class CAdapterInterface;
  92. private:
  93. CIpAddress * m_List;
  94. public:
  95. CIpAddressList(VOID) {
  96. m_List = NULL;
  97. }
  98. ~CIpAddressList() {
  99. Clear();
  100. }
  101. CIpAddress *
  102. Find(
  103. IN DWORD dwIpAddress,
  104. IN DWORD dwIpMask = INADDR_ANY
  105. );
  106. BOOL
  107. IsContextInList(
  108. IN DWORD dwContext
  109. );
  110. VOID
  111. Add(
  112. CIpAddress * pAddress
  113. );
  114. BOOL
  115. Add(
  116. IN DWORD dwIpAddress = INADDR_ANY,
  117. IN DWORD dwIpMask = INADDR_ANY,
  118. IN DWORD dwContext = 0
  119. );
  120. BOOL
  121. GetAddress(
  122. IN OUT LPDWORD lpdwIndex,
  123. OUT LPBYTE lpbAddress,
  124. IN OUT LPDWORD lpdwAddressLength
  125. );
  126. VOID SetFound(BOOL bFound) {
  127. for (CIpAddress * pEntry = m_List;
  128. pEntry != NULL;
  129. pEntry = pEntry->m_Next) {
  130. pEntry->SetFound(bFound);
  131. }
  132. }
  133. VOID Clear(VOID) {
  134. CIpAddress * pEntry;
  135. while ((pEntry = m_List) != NULL) {
  136. m_List = pEntry->m_Next;
  137. delete pEntry;
  138. }
  139. }
  140. BOOL IsEmpty(VOID) {
  141. return (m_List == NULL) ? TRUE : FALSE;
  142. }
  143. BOOL
  144. ThrowOutUnfoundEntries(
  145. VOID
  146. );
  147. };
  148. //
  149. // CAdapterInterface - singly-linked list of interface descriptors
  150. //
  151. class CAdapterInterface {
  152. friend class CIpConfig;
  153. private:
  154. LIST_ENTRY m_List;
  155. LPSTR m_lpszDescription;
  156. DWORD m_dwDescriptionLength;
  157. BYTE m_dwPhysicalAddressType;
  158. LPBYTE m_lpPhysicalAddress;
  159. DWORD m_dwPhysicalAddressLength;
  160. LPSTR m_lpszAdapterName;
  161. DWORD m_dwIndex;
  162. DWORD m_dwType;
  163. DWORD m_dwSpeed;
  164. union {
  165. struct {
  166. unsigned Found : 1;
  167. unsigned DialUp : 1;
  168. unsigned Dhcp : 1;
  169. } Bits;
  170. DWORD Word;
  171. } m_Flags;
  172. CIpAddressList m_IpList;
  173. //CIpAddressList m_RouterList; // do we still care about this one? no, we don't need it
  174. //CIpAddressList m_DnsList; // was never used to begin with
  175. CIpAddressList m_DhcpList;
  176. public:
  177. CAdapterInterface(
  178. IN DWORD dwIndex = 0,
  179. IN DWORD dwType = 0,
  180. IN DWORD dwSpeed = (DWORD)-1,
  181. IN LPSTR lpszDescription = NULL,
  182. IN DWORD dwDescriptionLength = 0,
  183. IN LPBYTE lpPhysicalAddress = NULL,
  184. IN DWORD dwPhysicalAddressLength = 0
  185. );
  186. ~CAdapterInterface();
  187. BOOL IsFound(VOID) {
  188. return m_Flags.Bits.Found ? TRUE : FALSE;
  189. }
  190. VOID SetFound(BOOL bFound) {
  191. m_Flags.Bits.Found = bFound ? 1 : 0;
  192. }
  193. BOOL IsDialUp(VOID) {
  194. return m_Flags.Bits.DialUp ? TRUE : FALSE;
  195. }
  196. VOID SetDialUp(VOID) {
  197. m_Flags.Bits.DialUp = 1;
  198. }
  199. BOOL IsDhcp(VOID) {
  200. return m_Flags.Bits.Dhcp ? TRUE : FALSE;
  201. }
  202. VOID SetDhcp(VOID) {
  203. m_Flags.Bits.Dhcp = 1;
  204. }
  205. VOID SetNotFound(VOID) {
  206. SetFound(FALSE);
  207. m_IpList.SetFound(FALSE);
  208. //m_RouterList.SetFound(FALSE);
  209. //m_DnsList.SetFound(FALSE);
  210. }
  211. BOOL FindIpAddress(DWORD dwIpAddress) {
  212. return (m_IpList.Find(dwIpAddress) != NULL) ? TRUE : FALSE;
  213. }
  214. BOOL IsHardwareAddress(LPBYTE lpHardwareAddress) {
  215. return ( m_lpPhysicalAddress ?
  216. !memcmp(m_lpPhysicalAddress,
  217. lpHardwareAddress,
  218. m_dwPhysicalAddressLength
  219. )
  220. : FALSE );
  221. }
  222. BOOL IsContextInIPAddrList(IN DWORD dwContext) {
  223. return (m_IpList.IsContextInList(dwContext));
  224. }
  225. BOOL AddDhcpServer(DWORD dwIpAddress) {
  226. return m_DhcpList.Add(dwIpAddress);
  227. }
  228. VOID ClearDhcpServerList(VOID) {
  229. m_DhcpList.Clear();
  230. }
  231. BOOL SetAdapterName(LPSTR lpszNewAdapterName) {
  232. m_lpszAdapterName = NewString(lpszNewAdapterName);
  233. return (m_lpszAdapterName ? TRUE : FALSE);
  234. }
  235. LPSTR GetAdapterName(VOID) {
  236. return m_lpszAdapterName;
  237. }
  238. BOOL CopyAdapterInfoToDhcpContext(PDHCP_CONTEXT pDhcpContext);
  239. BOOL
  240. DhcpDoInformNT5(
  241. IN OUT LPSTR lpszAutoProxyUrl,
  242. IN DWORD dwAutoProxyUrlLength
  243. );
  244. };
  245. //
  246. // CIpConfig - maintains all info about IP interfaces on this machine
  247. //
  248. class CIpConfig {
  249. private:
  250. LIST_ENTRY m_List;
  251. DWORD m_dwNumberOfInterfaces;
  252. TRI_STATE m_Loaded;
  253. CIpAddressList m_DnsList;
  254. DWORD
  255. LoadEntryPoints(
  256. VOID
  257. );
  258. DWORD
  259. UnloadEntryPoints(
  260. VOID
  261. );
  262. BOOL EntryPointsLoaded(VOID) const {
  263. return m_Loaded;
  264. }
  265. BOOL
  266. GetAdapterList(
  267. OUT LPBOOL lpbChanged = NULL
  268. );
  269. BOOL
  270. GetAdapterListOnNT5(
  271. OUT LPBOOL lpbChanged = NULL
  272. );
  273. CAdapterInterface *
  274. FindOrCreateInterface(
  275. IN DWORD dwIndex,
  276. IN DWORD dwType,
  277. IN DWORD dwSpeed,
  278. IN LPSTR lpszDescription,
  279. IN DWORD dwDescriptionLength,
  280. IN LPBYTE lpPhysicalAddress,
  281. IN DWORD dwPhysicalAddressLength
  282. );
  283. CAdapterInterface *
  284. FindInterface(
  285. IN DWORD dwIndex
  286. );
  287. VOID SetNotFound(VOID) {
  288. //
  289. // ASSUMES: address of list entry in CAdapterInterface is same as
  290. // address of CAdapterInterface
  291. //
  292. for (CAdapterInterface * pEntry = (CAdapterInterface *)m_List.Flink;
  293. pEntry != (CAdapterInterface *)&m_List.Flink;
  294. pEntry = (CAdapterInterface *)pEntry->m_List.Flink) {
  295. pEntry->SetNotFound();
  296. }
  297. m_DnsList.SetFound(FALSE);
  298. }
  299. BOOL
  300. ThrowOutUnfoundEntries(
  301. VOID
  302. );
  303. BOOL
  304. ThrowOutUnfoundAddresses(
  305. VOID
  306. );
  307. public:
  308. CIpConfig(VOID);
  309. ~CIpConfig();
  310. BOOL
  311. GetRouterAddress(
  312. IN LPBYTE lpbInterfaceAddress OPTIONAL,
  313. IN DWORD dwInterfaceAddressLength,
  314. IN OUT LPDWORD lpdwIndex,
  315. OUT LPBYTE lpbAddress,
  316. IN OUT LPDWORD lpdwAddressLength
  317. );
  318. BOOL
  319. GetDnsAddress(
  320. IN LPBYTE lpbInterfaceAddress OPTIONAL,
  321. IN DWORD dwInterfaceAddressLength,
  322. IN OUT LPDWORD lpdwIndex,
  323. OUT LPBYTE lpbAddress,
  324. IN OUT LPDWORD lpdwAddressLength
  325. );
  326. BOOL
  327. IsKnownIpAddress(
  328. IN LPBYTE lpbInterfaceAddress OPTIONAL,
  329. IN DWORD dwInterfaceAddressLength,
  330. IN LPBYTE lpbAddress,
  331. IN DWORD dwAddressLength
  332. );
  333. BOOL
  334. Refresh(
  335. VOID
  336. );
  337. VOID
  338. GetAdapterInfo(
  339. VOID
  340. );
  341. BOOL
  342. DoInformsOnEachInterface(
  343. IN OUT LPSTR lpszAutoProxyUrl,
  344. IN DWORD dwAutoProxyUrlLength
  345. );
  346. };
  347. //
  348. // Function declarations
  349. //
  350. LPSTR* GetBoundAdapterList(HKEY BindingsSectionKey);
  351. BOOL OpenAdapterKey(DWORD KeyType, LPSTR Name, PHKEY Key);
  352. BOOL ReadRegistryDword(HKEY Key, LPSTR ParameterName, LPDWORD Value);
  353. BOOL ReadRegistryString(HKEY Key, LPSTR ParameterName, LPSTR String, LPDWORD Length);
  354. UINT GetDhcpServerFromDhcp(IN OUT CAdapterInterface * paiInterface);
  355. BOOL DhcpDoInform( // send an inform packet if necessary
  356. IN CAdapterInterface * pAdapterInterface,
  357. IN BOOL fBroadcast, // Do we broadcast this inform, or unicast to server?
  358. OUT LPSTR lpszAutoProxyUrl,
  359. IN DWORD dwAutoProxyUrlLength
  360. );
  361. DWORD
  362. QueryWellKnownDnsName(
  363. IN OUT LPSTR lpszAutoProxyUrl,
  364. IN DWORD dwAutoProxyUrlLength
  365. );
  366. //
  367. // global data
  368. //
  369. //extern CIpConfig * GlobalIpConfig;
  370. extern const char SERVICES_KEY_NAME[];
  371. #endif // IPCONFIG_H_