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.

352 lines
6.8 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. precomp.h
  5. Abstract:
  6. precompiled header
  7. --*/
  8. #include <nt.h>
  9. #include <ntrtl.h>
  10. #include <nturtl.h>
  11. #include <windows.h>
  12. //
  13. // set compiler warning settings
  14. //
  15. #pragma warning( disable: 4127 )
  16. // allow while( 0 ) etc.
  17. #pragma warning( disable: 4221 )
  18. #pragma warning( disable: 4204 )
  19. // allow initializations for structs with variables
  20. #pragma warning( disable: 4201 )
  21. // allow structs with no names
  22. #pragma warning( disable: 4245 )
  23. // allow initialization time unsigned/signed mismatch
  24. #pragma warning( disable: 4232 )
  25. // allow initialization of structs with fn ptrs from dllimport
  26. #pragma warning( disable: 4214 )
  27. // allow bit fields in structs
  28. #include <winsock2.h>
  29. #include <ws2tcpip.h>
  30. #include <mstcpip.h>
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <align.h>
  35. #include <iphlpapi.h>
  36. #include <tchar.h>
  37. #include <rtutils.h>
  38. #include <windns.h>
  39. #include <dnsapi.h>
  40. //
  41. // set compiler warning settings
  42. //
  43. #pragma warning( disable: 4127 )
  44. // allow while( 0 ) etc.
  45. #pragma warning( disable: 4221 )
  46. #pragma warning( disable: 4204 )
  47. // allow initializations for structs with variables
  48. #pragma warning( disable: 4201 )
  49. // allow structs with no names
  50. #pragma warning( disable: 4245 )
  51. // allow initialization time unsigned/signed mismatch
  52. #pragma warning( disable: 4232 )
  53. // allow initialization of structs with fn ptrs from dllimport
  54. #pragma warning( disable: 4214 )
  55. // allow bit fields in structs
  56. #include <guiddef.h>
  57. #include <devguid.h>
  58. #include <setupapi.h>
  59. #include <netconp.h>
  60. #include <ntddtcp.h>
  61. #include <ntddip.h>
  62. #include <tdistat.h>
  63. #include <tdiinfo.h>
  64. #include <llinfo.h>
  65. #include <ipinfo.h>
  66. #include <ipexport.h>
  67. #include <nbtioctl.h>
  68. #pragma warning( disable: 4200 )
  69. // allow zero sized arrays
  70. #include <nhapi.h>
  71. #include <iphlpstk.h>
  72. #include <ndispnp.h>
  73. #include <ipconfig.h>
  74. #include <ntddip6.h>
  75. #pragma warning(disable:4001)
  76. #pragma warning(disable:4201)
  77. #pragma warning(disable:4214)
  78. #pragma warning(disable:4514)
  79. //
  80. // This structure has global information only
  81. //
  82. #define MaxHostNameSize 256
  83. #define MaxDomainNameSize 256
  84. #define MaxScopeIdSize 256
  85. #define MaxPhysicalNameSize 256
  86. #define MaxDeviceGuidName 256
  87. #ifndef IPV4_ADDRESS_DEFINED
  88. typedef DWORD IPV4_ADDRESS;
  89. #endif
  90. typedef struct _INTERFACE_NETWORK_INFO {
  91. //
  92. // General device info
  93. //
  94. WCHAR DeviceGuidName[MaxDeviceGuidName];
  95. DWORD IfType;
  96. CHAR PhysicalName[MaxPhysicalNameSize];
  97. DWORD PhysicalNameLength;
  98. LPWSTR FriendlyName;
  99. LPWSTR ConnectionName;
  100. BOOL MediaDisconnected;
  101. //
  102. // Dhcp specific info
  103. //
  104. LPWSTR DhcpClassId;
  105. BOOL EnableDhcp;
  106. BOOL EnableAutoconfig;
  107. IPV4_ADDRESS DhcpServer;
  108. LONGLONG LeaseObtainedTime; // these are actually FILETIMEs but made them...
  109. LONGLONG LeaseExpiresTime; // ...LONGLONG to fix alignment pb on W64 (#120397)
  110. BOOL AutoconfigActive;
  111. //
  112. // Dns specific info
  113. //
  114. IPV4_ADDRESS *DnsServer; // network order
  115. ULONG nDnsServers;
  116. SOCKADDR_IN6 *Ipv6DnsServer;
  117. ULONG nIpv6DnsServers;
  118. WCHAR DnsSuffix[MaxDomainNameSize];
  119. //
  120. // Wins specific Info
  121. //
  122. IPV4_ADDRESS *WinsServer; // network order
  123. ULONG nWinsServers;
  124. BOOL EnableNbtOverTcpip;
  125. //
  126. // Ip specific info: first ip is primary addr
  127. //
  128. IPV4_ADDRESS *IpAddress; // network order
  129. ULONG nIpAddresses;
  130. SOCKADDR_IN6 *Ipv6Address;
  131. ULONG nIpv6Addresses;
  132. IPV4_ADDRESS *IpMask; // network order
  133. ULONG nIpMasks;
  134. IPV4_ADDRESS *Router; // network order
  135. ULONG nRouters;
  136. SOCKADDR_IN6 *Ipv6Router;
  137. ULONG nIpv6Routers;
  138. } INTERFACE_NETWORK_INFO, *PINTERFACE_NETWORK_INFO;
  139. typedef struct _NETWORK_INFO {
  140. WCHAR HostName[MaxHostNameSize];
  141. WCHAR DomainName[MaxDomainNameSize];
  142. WCHAR ScopeId[MaxScopeIdSize];
  143. ULONG NodeType;
  144. BOOL EnableRouting;
  145. BOOL EnableProxy;
  146. BOOL EnableDnsForNetbios;
  147. BOOL GlobalEnableAutoconfig;
  148. LPWSTR SuffixSearchList; // Multi_Sz string
  149. ULONG nInterfaces;
  150. PINTERFACE_NETWORK_INFO *IfInfo;
  151. } NETWORK_INFO, *PNETWORK_INFO;
  152. //
  153. // Node Type values
  154. //
  155. enum {
  156. NodeTypeUnknown = 0,
  157. NodeTypeBroadcast,
  158. NodeTypePeerPeer,
  159. NodeTypeMixed,
  160. NodeTypeHybrid
  161. };
  162. //
  163. // IfType values
  164. //
  165. enum {
  166. IfTypeUnknown = 0,
  167. IfTypeOther,
  168. IfTypeEthernet,
  169. IfTypeTokenring,
  170. IfTypeFddi,
  171. IfTypeLoopback,
  172. IfTypePPP,
  173. IfTypeSlip,
  174. IfTypeTunnel,
  175. IfType1394
  176. } IfTypeConstants;
  177. //
  178. // Internal error codes
  179. //
  180. enum {
  181. GlobalHostNameFailure = 0,
  182. GlobalDomainNameFailure = 2,
  183. GlobalEnableRouterFailure = 3,
  184. GlobalEnableDnsFailure = 4,
  185. GlobalIfTableFailure = 5,
  186. GlobalIfInfoFailure = 6,
  187. GlobalIfNameInfoFailure = 7,
  188. GlobalAddrTableFailure = 8,
  189. GlobalRouteTableFailure = 9,
  190. InterfaceUnknownType = 10,
  191. InterfaceUnknownFriendlyName = 11,
  192. InterfaceUnknownMediaStatus = 12,
  193. InterfaceUnknownTcpipDevice = 13,
  194. InterfaceOpenTcpipKeyReadFailure = 14,
  195. InterfaceDhcpValuesFailure = 15,
  196. InterfaceDnsValuesFailure = 16,
  197. InterfaceWinsValuesFailure = 17,
  198. InterfaceAddressValuesFailure = 18,
  199. InterfaceRouteValuesFailure = 19,
  200. NoSpecificError = 20,
  201. } InternalFailureCodes;
  202. //
  203. // routines exported from info.c
  204. //
  205. enum {
  206. OpenTcpipParmKey,
  207. OpenTcpipKey,
  208. OpenNbtKey
  209. } KeyTypeEnums;
  210. enum {
  211. OpenKeyForRead = 0x01,
  212. OpenKeyForWrite = 0x02
  213. } AccessTypeEnums;
  214. DWORD
  215. OpenRegKey(
  216. IN LPCWSTR Device,
  217. IN DWORD KeyType,
  218. IN DWORD AccessType,
  219. OUT HKEY *phKey
  220. );
  221. VOID
  222. FreeNetworkInfo(
  223. IN OUT PNETWORK_INFO NetInfo
  224. );
  225. DWORD
  226. GetNetworkInformation(
  227. OUT PNETWORK_INFO *pNetInfo,
  228. IN OUT DWORD *InternalError
  229. );
  230. //
  231. // exported by display.c
  232. //
  233. typedef struct _CMD_ARGS {
  234. LPWSTR All, Renew, Release, FlushDns, Register;
  235. LPWSTR DisplayDns, ShowClassId, SetClassId;
  236. LPWSTR Debug, Usage, UsageErr;
  237. } CMD_ARGS, *PCMD_ARGS;
  238. DWORD
  239. GetCommandArgConstants(
  240. IN OUT PCMD_ARGS Args
  241. );
  242. DWORD
  243. FormatNetworkInfo(
  244. IN OUT LPWSTR Buffer,
  245. IN ULONG BufSize,
  246. IN PNETWORK_INFO NetInfo,
  247. IN DWORD Win32Error,
  248. IN DWORD InternalError,
  249. IN BOOL fVerbose,
  250. IN BOOL fDebug
  251. );
  252. DWORD
  253. DumpMessage(
  254. IN LPWSTR Buffer,
  255. IN ULONG BufSize,
  256. IN ULONG MsgId,
  257. ...
  258. );
  259. DWORD
  260. DumpMessageError(
  261. IN LPWSTR Buffer,
  262. IN ULONG BufSize,
  263. IN ULONG MsgId,
  264. IN ULONG_PTR Error,
  265. IN PVOID Arg OPTIONAL
  266. );
  267. DWORD
  268. DumpErrorMessage(
  269. IN LPWSTR Buffer,
  270. IN ULONG BufSize,
  271. IN ULONG InternalError,
  272. IN ULONG Win32Error
  273. );
  274. #ifdef __IPCFG_ENABLE_LOG__
  275. extern DWORD dwTraceFlag;
  276. extern int TraceFunc(const char* fmt, ...);
  277. #define IPCFG_TRACE_TCPIP 0x01U
  278. #define IPCFG_TRACE(x,y) \
  279. if (dwTraceFlag & x) { \
  280. TraceFunc y; \
  281. }
  282. #else
  283. #define IPCFG_TRACE(x,y)
  284. #endif