2002-06-06 18:50:12 +00:00
|
|
|
// The contents of this file are subject to the Mozilla Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://www.mozilla.org/MPL/
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2003-02-25 00:19:50 +00:00
|
|
|
#define _WIN32_WINNT 0x0400
|
|
|
|
|
2002-10-06 01:12:54 +00:00
|
|
|
#include <afxwin.h>
|
2003-01-29 23:10:46 +00:00
|
|
|
#include <winsock.h>
|
2002-06-06 18:50:12 +00:00
|
|
|
#include "client_types.h"
|
2002-10-28 19:04:13 +00:00
|
|
|
#include "hostinfo.h"
|
2003-03-10 19:05:25 +00:00
|
|
|
#include "util.h"
|
2002-06-06 18:50:12 +00:00
|
|
|
|
2002-12-11 23:10:51 +00:00
|
|
|
typedef BOOL (CALLBACK* FreeFn)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
|
2002-12-05 22:50:21 +00:00
|
|
|
|
2002-12-09 23:52:17 +00:00
|
|
|
// Returns the number of seconds difference from UTC
|
|
|
|
//
|
|
|
|
int get_timezone(void) {
|
|
|
|
TIME_ZONE_INFORMATION tzi;
|
|
|
|
ZeroMemory(&tzi, sizeof(TIME_ZONE_INFORMATION));
|
|
|
|
GetTimeZoneInformation(&tzi);
|
|
|
|
return (tzi.Bias * 60);
|
|
|
|
}
|
|
|
|
|
2002-12-11 23:10:51 +00:00
|
|
|
// Returns total and free space on current disk (in bytes)
|
|
|
|
//
|
|
|
|
void get_host_disk_info( double &total_space, double &free_space ) {
|
|
|
|
FreeFn pGetDiskFreeSpaceEx;
|
|
|
|
pGetDiskFreeSpaceEx = (FreeFn)GetProcAddress(GetModuleHandle("kernel32.dll"), "GetDiskFreeSpaceExA");
|
|
|
|
if(pGetDiskFreeSpaceEx) {
|
|
|
|
ULARGE_INTEGER TotalNumberOfFreeBytes;
|
|
|
|
ULARGE_INTEGER TotalNumberOfBytes;
|
|
|
|
pGetDiskFreeSpaceEx(NULL, NULL, &TotalNumberOfBytes, &TotalNumberOfFreeBytes);
|
|
|
|
unsigned int uMB;
|
|
|
|
uMB = TotalNumberOfFreeBytes.QuadPart / (1024 * 1024);
|
|
|
|
free_space = uMB * 1024.0 * 1024.0;
|
|
|
|
uMB = TotalNumberOfBytes.QuadPart / (1024 * 1024);
|
|
|
|
total_space = uMB * 1024.0 * 1024.0;
|
|
|
|
} else {
|
|
|
|
DWORD dwSectPerClust;
|
|
|
|
DWORD dwBytesPerSect;
|
|
|
|
DWORD dwFreeClusters;
|
|
|
|
DWORD dwTotalClusters;
|
|
|
|
GetDiskFreeSpace(NULL, &dwSectPerClust, &dwBytesPerSect, &dwFreeClusters, &dwTotalClusters);
|
|
|
|
free_space = (double)dwFreeClusters * dwSectPerClust * dwBytesPerSect;
|
|
|
|
total_space = (double)dwTotalClusters * dwSectPerClust * dwBytesPerSect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Gets windows specific host information (not complete)
|
|
|
|
//
|
2002-10-28 19:04:13 +00:00
|
|
|
int get_host_info(HOST_INFO& host) {
|
2002-06-06 18:50:12 +00:00
|
|
|
OSVERSIONINFO OSVersionInfo;
|
|
|
|
memset( &OSVersionInfo, NULL, sizeof( OSVersionInfo ) );
|
|
|
|
OSVersionInfo.dwOSVersionInfoSize = sizeof( OSVersionInfo );
|
|
|
|
::GetVersionEx( &OSVersionInfo );
|
|
|
|
switch ( OSVersionInfo.dwPlatformId ) {
|
|
|
|
case VER_PLATFORM_WIN32s:
|
|
|
|
strcpy( host.os_name, "Windows 3.1/Win32s" ); // does ANYBODY use this anymore?
|
|
|
|
break;
|
|
|
|
case VER_PLATFORM_WIN32_WINDOWS:
|
2002-08-14 23:02:32 +00:00
|
|
|
if ( OSVersionInfo.dwMajorVersion > 4
|
2002-10-02 22:05:19 +00:00
|
|
|
|| ( OSVersionInfo.dwMajorVersion == 4
|
|
|
|
&& OSVersionInfo.dwMinorVersion >= 90 ) )
|
2002-06-06 18:50:12 +00:00
|
|
|
{
|
2002-10-02 22:05:19 +00:00
|
|
|
strcpy( host.os_name, "Windows Me" );
|
|
|
|
}
|
|
|
|
else if ( OSVersionInfo.dwMajorVersion == 4
|
|
|
|
&& OSVersionInfo.dwMinorVersion >= 10 )
|
|
|
|
{
|
2002-06-06 18:50:12 +00:00
|
|
|
strcpy( host.os_name, "Windows 98" );
|
2002-10-02 22:05:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-06-06 18:50:12 +00:00
|
|
|
strcpy( host.os_name, "Windows 95" );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VER_PLATFORM_WIN32_NT:
|
2002-10-02 22:05:19 +00:00
|
|
|
if ( OSVersionInfo.dwMajorVersion > 5
|
|
|
|
|| (OSVersionInfo.dwMajorVersion == 5
|
|
|
|
&& OSVersionInfo.dwMinorVersion >= 2) )
|
|
|
|
{
|
|
|
|
strcpy( host.os_name, "Windows .NET Server" );
|
|
|
|
}
|
|
|
|
else if (OSVersionInfo.dwMajorVersion == 5
|
|
|
|
&& OSVersionInfo.dwMinorVersion == 1)
|
|
|
|
{
|
|
|
|
strcpy( host.os_name, "Windows XP" );
|
|
|
|
}
|
|
|
|
else if (OSVersionInfo.dwMajorVersion == 5
|
|
|
|
&& OSVersionInfo.dwMinorVersion == 0)
|
|
|
|
{
|
|
|
|
strcpy( host.os_name, "Windows 2000" );
|
|
|
|
}
|
|
|
|
else if (OSVersionInfo.dwMajorVersion == 4
|
|
|
|
&& OSVersionInfo.dwMinorVersion == 0)
|
|
|
|
{
|
|
|
|
strcpy( host.os_name, "Windows NT 4.0" );
|
|
|
|
}
|
|
|
|
else if (OSVersionInfo.dwMajorVersion == 3
|
|
|
|
&& OSVersionInfo.dwMinorVersion == 51)
|
|
|
|
{
|
|
|
|
strcpy( host.os_name, "Windows NT 3.51" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy( host.os_name, "Windows NT" );
|
|
|
|
}
|
2002-06-06 18:50:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
sprintf( host.os_name, "Unknown Win32 (%ld)", OSVersionInfo.dwPlatformId );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
char Version[ 25 ];
|
|
|
|
Version[ 0 ] = NULL;
|
2002-08-14 23:02:32 +00:00
|
|
|
sprintf(
|
2002-12-09 23:52:17 +00:00
|
|
|
Version, "%lu.%lu", OSVersionInfo.dwMajorVersion,
|
2002-08-14 23:02:32 +00:00
|
|
|
OSVersionInfo.dwMinorVersion
|
|
|
|
);
|
2003-03-10 19:05:25 +00:00
|
|
|
safe_strncpy( host.os_version, Version, sizeof(host.os_version) );
|
2002-06-06 18:50:12 +00:00
|
|
|
|
|
|
|
SYSTEM_INFO SystemInfo;
|
|
|
|
memset( &SystemInfo, NULL, sizeof( SystemInfo ) );
|
|
|
|
::GetSystemInfo( &SystemInfo );
|
2002-10-02 22:05:19 +00:00
|
|
|
|
|
|
|
host.p_ncpus = SystemInfo.dwNumberOfProcessors;
|
|
|
|
|
2002-06-06 18:50:12 +00:00
|
|
|
switch ( SystemInfo.wProcessorArchitecture ) {
|
2002-10-02 22:05:19 +00:00
|
|
|
case PROCESSOR_ARCHITECTURE_INTEL:
|
2002-06-06 18:50:12 +00:00
|
|
|
switch ( SystemInfo.dwProcessorType ) {
|
2002-10-02 22:05:19 +00:00
|
|
|
case PROCESSOR_INTEL_386:
|
2002-12-13 23:30:17 +00:00
|
|
|
strcpy( host.p_model, "80386" );
|
2002-10-02 22:05:19 +00:00
|
|
|
break;
|
|
|
|
case PROCESSOR_INTEL_486:
|
2002-12-13 23:30:17 +00:00
|
|
|
strcpy( host.p_model, "80486" );
|
2002-10-02 22:05:19 +00:00
|
|
|
break;
|
|
|
|
case PROCESSOR_INTEL_PENTIUM:
|
2002-12-13 23:30:17 +00:00
|
|
|
strcpy( host.p_model, "Pentium" );
|
2002-10-02 22:05:19 +00:00
|
|
|
break;
|
|
|
|
default:
|
2002-12-13 23:30:17 +00:00
|
|
|
strcpy( host.p_model, "x86" );
|
2002-10-02 22:05:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-06-06 18:50:12 +00:00
|
|
|
break;
|
|
|
|
|
2002-10-02 22:05:19 +00:00
|
|
|
case PROCESSOR_ARCHITECTURE_MIPS:
|
|
|
|
strcpy( host.p_model, "MIPS" );
|
|
|
|
break;
|
2002-06-06 18:50:12 +00:00
|
|
|
|
2002-10-02 22:05:19 +00:00
|
|
|
case PROCESSOR_ARCHITECTURE_ALPHA:
|
|
|
|
strcpy( host.p_model, "Alpha" );
|
|
|
|
break;
|
2002-06-06 18:50:12 +00:00
|
|
|
|
2002-10-02 22:05:19 +00:00
|
|
|
case PROCESSOR_ARCHITECTURE_PPC:
|
|
|
|
strcpy( host.p_model, "Power PC" );
|
|
|
|
break;
|
2002-06-06 18:50:12 +00:00
|
|
|
|
2002-10-02 22:05:19 +00:00
|
|
|
case PROCESSOR_ARCHITECTURE_UNKNOWN:
|
|
|
|
default:
|
|
|
|
strcpy( host.p_model, "Unknown" );
|
|
|
|
break;
|
2002-06-06 18:50:12 +00:00
|
|
|
}
|
|
|
|
|
2002-12-11 23:10:51 +00:00
|
|
|
get_host_disk_info(host.d_total, host.d_free);
|
2003-01-29 23:10:46 +00:00
|
|
|
|
|
|
|
// Open the WinSock dll so we can get host info
|
|
|
|
WORD wVersionRequested;
|
|
|
|
WSADATA wsdata;
|
|
|
|
wVersionRequested = MAKEWORD(1, 1);
|
|
|
|
WSAStartup(wVersionRequested, &wsdata);
|
|
|
|
|
|
|
|
// Get host name/ip info
|
2003-03-10 19:05:25 +00:00
|
|
|
get_local_domain_name(host.domain_name, sizeof(host.domain_name));
|
|
|
|
get_local_ip_addr_str(host.ip_addr, sizeof(host.ip_addr));
|
2002-06-06 18:50:12 +00:00
|
|
|
|
2003-01-29 23:10:46 +00:00
|
|
|
// Close the WinSock dll
|
|
|
|
WSACleanup();
|
|
|
|
|
2002-12-09 23:52:17 +00:00
|
|
|
host.timezone = get_timezone();
|
|
|
|
|
|
|
|
MEMORYSTATUS mStatus;
|
|
|
|
ZeroMemory(&mStatus, sizeof(MEMORYSTATUS));
|
|
|
|
mStatus.dwLength = sizeof(MEMORYSTATUS);
|
|
|
|
GlobalMemoryStatus(&mStatus);
|
|
|
|
host.m_nbytes = (double)mStatus.dwTotalPhys;
|
|
|
|
host.m_swap = (double)mStatus.dwTotalPageFile;
|
|
|
|
|
|
|
|
// gets processor vendor name from registry, works for intel
|
2003-04-02 19:59:13 +00:00
|
|
|
char vendorName[256], procNameString[256];
|
2002-12-09 23:52:17 +00:00
|
|
|
HKEY hKey;
|
|
|
|
LONG retval;
|
2003-04-02 19:59:13 +00:00
|
|
|
DWORD nameSize, procSpeed;
|
|
|
|
bool gotProcName = false, gotMHz = false, gotVendIdent = false;
|
|
|
|
|
2002-12-09 23:52:17 +00:00
|
|
|
retval = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Hardware\\Description\\System\\CentralProcessor\\0", 0, KEY_QUERY_VALUE, &hKey);
|
|
|
|
if(retval == ERROR_SUCCESS) {
|
2003-04-02 19:59:13 +00:00
|
|
|
// Look in various places for processor information, add'l
|
|
|
|
// entries suggested by mark mcclure
|
|
|
|
nameSize = sizeof(procNameString);
|
|
|
|
retval = RegQueryValueEx(hKey, "ProcessorNameString", NULL, NULL, (LPBYTE)procNameString, &nameSize);
|
|
|
|
if (retval == ERROR_SUCCESS) gotProcName = true;
|
|
|
|
|
2002-12-09 23:52:17 +00:00
|
|
|
nameSize = sizeof(vendorName);
|
|
|
|
retval = RegQueryValueEx(hKey, "VendorIdentifier", NULL, NULL, (LPBYTE)vendorName, &nameSize);
|
2003-04-02 19:59:13 +00:00
|
|
|
if (retval == ERROR_SUCCESS) gotVendIdent = true;
|
|
|
|
else strcpy( "Unknown", vendorName );
|
|
|
|
|
|
|
|
nameSize = sizeof(DWORD);
|
|
|
|
retval = RegQueryValueEx(hKey, "~MHz", NULL, NULL, (LPBYTE)&procSpeed, &nameSize);
|
|
|
|
if (retval == ERROR_SUCCESS) gotMHz = true;
|
2002-12-09 23:52:17 +00:00
|
|
|
}
|
2003-04-02 19:59:13 +00:00
|
|
|
if (gotProcName) safe_strncpy( host.p_vendor, procNameString, sizeof(host.p_vendor) );
|
|
|
|
else if (gotMHz) sprintf( host.p_vendor, "%s %dMHz", vendorName, procSpeed );
|
|
|
|
else safe_strncpy( host.p_vendor, vendorName, sizeof(host.p_vendor) );
|
|
|
|
|
2002-12-09 23:52:17 +00:00
|
|
|
RegCloseKey(hKey);
|
2002-06-06 18:50:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2002-10-06 01:12:54 +00:00
|
|
|
|
2002-10-28 19:31:34 +00:00
|
|
|
bool host_is_running_on_batteries() {
|
2002-12-09 23:52:17 +00:00
|
|
|
SYSTEM_POWER_STATUS pStatus;
|
|
|
|
ZeroMemory(&pStatus, sizeof(SYSTEM_POWER_STATUS));
|
2003-02-25 00:19:50 +00:00
|
|
|
if (!GetSystemPowerStatus(&pStatus)) {
|
|
|
|
printf( "Got error: %d\n", GetLastError());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-12-09 23:52:17 +00:00
|
|
|
return (pStatus.ACLineStatus != 1);
|
2002-12-05 22:50:21 +00:00
|
|
|
}
|