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.

186 lines
4.8 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <dnsapi.h>
  8. #include "..\dnslib.h"
  9. BOOL DisplaySystemVersion();
  10. VOID
  11. PrintIpAddress (
  12. IN DWORD dwIpAddress )
  13. {
  14. printf( " %d.%d.%d.%d\n",
  15. ((BYTE *) &dwIpAddress)[0],
  16. ((BYTE *) &dwIpAddress)[1],
  17. ((BYTE *) &dwIpAddress)[2],
  18. ((BYTE *) &dwIpAddress)[3] );
  19. }
  20. VOID
  21. PrintAddressInfo (
  22. IN DNS_ADDRESS_INFO AddressInfo )
  23. {
  24. printf( " ipAddress : " );
  25. PrintIpAddress( AddressInfo.ipAddress );
  26. printf( " subnetMask : " );
  27. PrintIpAddress( AddressInfo.subnetMask );
  28. printf( "\n" );
  29. }
  30. _cdecl
  31. main(int argc, char **argv)
  32. {
  33. DNS_ADDRESS_INFO AddressInfoList[256];
  34. DWORD Count;
  35. DWORD sysVersion;
  36. DWORD iter;
  37. PIP_ARRAY pIp = NULL;
  38. DisplaySystemVersion();
  39. DnsStartDebug( 0,
  40. "listadp.flag",
  41. NULL,
  42. NULL,
  43. 0 );
  44. Dns_InitNetworkInfo();
  45. sysVersion = GetVersion();
  46. printf( "System version is : 0x%x\n", sysVersion );
  47. printf( "\n Calling Dns_GetLocalIpAddressArray . . . \n" );
  48. pIp = Dns_GetLocalIpAddressArray();
  49. for ( iter = 0; iter < pIp->cAddrCount; iter++ )
  50. {
  51. printf( "(%d) ", iter+1 );
  52. PrintIpAddress( pIp->aipAddrs[iter] );
  53. }
  54. printf( "\n Calling Dns_GetIpAddresses . . . \n" );
  55. Count = Dns_GetIpAddresses( AddressInfoList, 256 );
  56. if ( !Count )
  57. {
  58. printf( "\n Dns_GetIpAddresses call failed\n" );
  59. return(0);
  60. }
  61. for ( iter = 0; iter < Count; iter++ )
  62. {
  63. printf( "(%d) ", iter+1 );
  64. PrintAddressInfo( AddressInfoList[iter] );
  65. }
  66. return(0);
  67. }
  68. BOOL DisplaySystemVersion()
  69. {
  70. OSVERSIONINFOEX osvi;
  71. BOOL bOsVersionInfoEx;
  72. // Try calling GetVersionEx using the OSVERSIONINFOEX structure,
  73. // which is supported on Windows 2000.
  74. //
  75. // If that fails, try using the OSVERSIONINFO structure.
  76. ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
  77. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  78. if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
  79. {
  80. // If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO.
  81. osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
  82. if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
  83. {
  84. printf( "GetVersionEx function call failed, might be Win9x?\n" );
  85. return FALSE;
  86. }
  87. }
  88. switch (osvi.dwPlatformId)
  89. {
  90. case VER_PLATFORM_WIN32_NT:
  91. // Test for the product.
  92. if ( osvi.dwMajorVersion <= 4 )
  93. printf( "Microsoft Windows NT ");
  94. if ( osvi.dwMajorVersion == 5 )
  95. printf ("Microsoft Windows 2000 ");
  96. if ( osvi.dwMajorVersion > 5 )
  97. printf ("Microsoft Windows (9x?) ");
  98. // Test for workstation versus server.
  99. if( bOsVersionInfoEx )
  100. {
  101. printf( "psvi.wPtroductType: %x\n", osvi.wProductType );
  102. if ( osvi.wProductType == VER_NT_WORKSTATION )
  103. printf ( "Professional " );
  104. if ( osvi.wProductType == VER_NT_SERVER )
  105. printf ( "Server " );
  106. if ( osvi.wProductType == VER_NT_DOMAIN_CONTROLLER )
  107. printf ( "Domain Controller " );
  108. }
  109. else
  110. {
  111. HKEY hKey;
  112. char szProductType[80];
  113. DWORD dwBufLen;
  114. RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  115. "SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
  116. 0, KEY_QUERY_VALUE, &hKey );
  117. RegQueryValueEx( hKey, "ProductType", NULL, NULL,
  118. (LPBYTE) szProductType, &dwBufLen);
  119. RegCloseKey( hKey );
  120. if ( lstrcmpi( "WINNT", szProductType) == 0 )
  121. printf( "Workstation " );
  122. if ( lstrcmpi( "SERVERNT", szProductType) == 0 )
  123. printf( "Server " );
  124. }
  125. // Display version, service pack (if any), and build number.
  126. printf ("version %d.%d %s (Build %d)\n",
  127. osvi.dwMajorVersion,
  128. osvi.dwMinorVersion,
  129. osvi.szCSDVersion,
  130. osvi.dwBuildNumber & 0xFFFF);
  131. break;
  132. case VER_PLATFORM_WIN32_WINDOWS:
  133. if ((osvi.dwMajorVersion > 4) ||
  134. ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion > 0)))
  135. {
  136. printf ("Microsoft Windows 98 ");
  137. }
  138. else printf ("Microsoft Windows 95 ");
  139. break;
  140. case VER_PLATFORM_WIN32s:
  141. printf ("Microsoft Win32s ");
  142. break;
  143. }
  144. return TRUE;
  145. }