2003-06-11 23:36:48 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
2002-04-30 22:22:54 +00:00
|
|
|
// 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
|
2003-06-11 23:36:48 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2003-08-08 23:41:36 +00:00
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// 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
|
2003-08-08 23:41:36 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2003-08-08 23:41:36 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2002-10-28 19:04:13 +00:00
|
|
|
#if HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_NETDB_H
|
|
|
|
#include <netdb.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_ARPA_INET_H
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_NETINET_IN_H
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
|
2002-10-28 19:31:34 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <winsock.h>
|
|
|
|
#endif
|
|
|
|
|
2003-03-06 00:42:18 +00:00
|
|
|
#include "util.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "parse.h"
|
2003-07-03 05:01:29 +00:00
|
|
|
#include "message.h"
|
2002-07-11 01:09:53 +00:00
|
|
|
#include "error_numbers.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-07-03 05:01:29 +00:00
|
|
|
#include "hostinfo.h"
|
|
|
|
|
2002-10-28 19:31:34 +00:00
|
|
|
// Reset the host info struct to default values
|
|
|
|
//
|
|
|
|
void clear_host_info(HOST_INFO& host) {
|
2002-11-19 22:57:05 +00:00
|
|
|
host.timezone = 0; // seconds added to local time to get UTC
|
2003-03-19 01:15:46 +00:00
|
|
|
strcpy(host.domain_name, "");
|
|
|
|
strcpy(host.serialnum, "");
|
|
|
|
strcpy(host.ip_addr, "");
|
2002-10-28 19:31:34 +00:00
|
|
|
|
|
|
|
host.p_ncpus = 0;
|
2003-03-19 01:15:46 +00:00
|
|
|
strcpy(host.p_vendor, "");
|
|
|
|
strcpy(host.p_model, "");
|
2002-10-28 19:31:34 +00:00
|
|
|
host.p_fpops = 0;
|
|
|
|
host.p_iops = 0;
|
|
|
|
host.p_membw = 0;
|
2003-07-01 23:16:53 +00:00
|
|
|
host.p_fpop_err = 0;
|
|
|
|
host.p_iop_err = 0;
|
|
|
|
host.p_membw_err = 0;
|
2002-10-28 19:31:34 +00:00
|
|
|
host.p_calculated = 0;
|
2003-08-08 23:41:36 +00:00
|
|
|
|
2003-03-19 01:15:46 +00:00
|
|
|
strcpy(host.os_name, "");
|
|
|
|
strcpy(host.os_version, "");
|
2002-10-28 19:31:34 +00:00
|
|
|
|
|
|
|
host.m_nbytes = 0;
|
|
|
|
host.m_cache = 0;
|
|
|
|
host.m_swap = 0;
|
|
|
|
|
|
|
|
host.d_total = 0;
|
|
|
|
host.d_free = 0;
|
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Parse the host information, usually from the client state XML file
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
int HOST_INFO::parse(FILE* in) {
|
|
|
|
char buf[256];
|
2002-08-15 22:03:41 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
memset(this, 0, sizeof(HOST_INFO));
|
|
|
|
while (fgets(buf, 256, in)) {
|
|
|
|
if (match_tag(buf, "</host_info>")) return 0;
|
|
|
|
else if (parse_int(buf, "<timezone>", timezone)) continue;
|
2002-09-22 23:27:14 +00:00
|
|
|
else if (parse_str(buf, "<domain_name>", domain_name, sizeof(domain_name))) continue;
|
|
|
|
else if (parse_str(buf, "<ip_addr>", ip_addr, sizeof(ip_addr))) continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
else if (parse_int(buf, "<p_ncpus>", p_ncpus)) continue;
|
2002-09-22 23:27:14 +00:00
|
|
|
else if (parse_str(buf, "<p_vendor>", p_vendor, sizeof(p_vendor))) continue;
|
|
|
|
else if (parse_str(buf, "<p_model>", p_model, sizeof(p_model))) continue;
|
2003-10-19 19:03:49 +00:00
|
|
|
else if (parse_double(buf, "<p_fpops>", p_fpops)) {
|
|
|
|
// fix foolishness that could result in negative value here
|
|
|
|
//
|
|
|
|
if (p_fpops < 0) p_fpops = -p_fpops;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (parse_double(buf, "<p_iops>", p_iops)) {
|
|
|
|
if (p_iops < 0) p_iops = -p_iops;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (parse_double(buf, "<p_membw>", p_membw)) {
|
|
|
|
if (p_membw < 0) p_membw = -p_membw;
|
|
|
|
continue;
|
|
|
|
}
|
2003-07-01 23:16:53 +00:00
|
|
|
else if (parse_int(buf, "<p_fpop_err>", p_fpop_err)) continue;
|
|
|
|
else if (parse_int(buf, "<p_iop_err>", p_iop_err)) continue;
|
|
|
|
else if (parse_int(buf, "<p_membw_err>", p_membw_err)) continue;
|
2002-11-19 22:57:05 +00:00
|
|
|
else if (parse_double(buf, "<p_calculated>", p_calculated)) continue;
|
2002-09-22 23:27:14 +00:00
|
|
|
else if (parse_str(buf, "<os_name>", os_name, sizeof(os_name))) continue;
|
|
|
|
else if (parse_str(buf, "<os_version>", os_version, sizeof(os_version))) continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
else if (parse_double(buf, "<m_nbytes>", m_nbytes)) continue;
|
|
|
|
else if (parse_double(buf, "<m_cache>", m_cache)) continue;
|
|
|
|
else if (parse_double(buf, "<m_swap>", m_swap)) continue;
|
|
|
|
else if (parse_double(buf, "<d_total>", d_total)) continue;
|
|
|
|
else if (parse_double(buf, "<d_free>", d_free)) continue;
|
2003-07-03 05:01:29 +00:00
|
|
|
else msg_printf(NULL, MSG_ERROR, "HOST_INFO::parse(): unrecognized: %s\n", buf);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Write the host information, usually to the client state XML file
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
int HOST_INFO::write(FILE* out) {
|
|
|
|
fprintf(out,
|
|
|
|
"<host_info>\n"
|
|
|
|
" <timezone>%d</timezone>\n"
|
|
|
|
" <domain_name>%s</domain_name>\n"
|
|
|
|
" <ip_addr>%s</ip_addr>\n"
|
|
|
|
" <p_ncpus>%d</p_ncpus>\n"
|
|
|
|
" <p_vendor>%s</p_vendor>\n"
|
|
|
|
" <p_model>%s</p_model>\n"
|
|
|
|
" <p_fpops>%f</p_fpops>\n"
|
|
|
|
" <p_iops>%f</p_iops>\n"
|
|
|
|
" <p_membw>%f</p_membw>\n"
|
2003-07-01 23:16:53 +00:00
|
|
|
" <p_fpop_err>%d</p_fpop_err>\n"
|
|
|
|
" <p_iop_err>%d</p_iop_err>\n"
|
|
|
|
" <p_membw_err>%d</p_membw_err>\n"
|
2002-11-19 22:57:05 +00:00
|
|
|
" <p_calculated>%f</p_calculated>\n"
|
2002-04-30 22:22:54 +00:00
|
|
|
" <os_name>%s</os_name>\n"
|
|
|
|
" <os_version>%s</os_version>\n"
|
|
|
|
" <m_nbytes>%f</m_nbytes>\n"
|
|
|
|
" <m_cache>%f</m_cache>\n"
|
|
|
|
" <m_swap>%f</m_swap>\n"
|
|
|
|
" <d_total>%f</d_total>\n"
|
|
|
|
" <d_free>%f</d_free>\n"
|
|
|
|
"</host_info>\n",
|
|
|
|
timezone,
|
|
|
|
domain_name,
|
|
|
|
ip_addr,
|
|
|
|
p_ncpus,
|
|
|
|
p_vendor,
|
|
|
|
p_model,
|
|
|
|
p_fpops,
|
|
|
|
p_iops,
|
|
|
|
p_membw,
|
2003-07-01 23:16:53 +00:00
|
|
|
p_fpop_err,
|
|
|
|
p_iop_err,
|
|
|
|
p_membw_err,
|
2003-08-08 23:41:36 +00:00
|
|
|
p_calculated,
|
2002-04-30 22:22:54 +00:00
|
|
|
os_name,
|
|
|
|
os_version,
|
|
|
|
m_nbytes,
|
|
|
|
m_cache,
|
|
|
|
m_swap,
|
|
|
|
d_total,
|
|
|
|
d_free
|
|
|
|
);
|
|
|
|
return 0;
|
|
|
|
}
|
2002-10-28 19:04:13 +00:00
|
|
|
|
2003-04-01 03:28:37 +00:00
|
|
|
// CPU benchmarks are run in a separate process,
|
|
|
|
// which communicates its result via a file.
|
|
|
|
// The following functions read and write this file.
|
2002-12-09 23:51:55 +00:00
|
|
|
//
|
2003-04-01 03:28:37 +00:00
|
|
|
int HOST_INFO::parse_cpu_benchmarks(FILE* in) {
|
2002-12-09 23:51:55 +00:00
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
fgets(buf, 256, in);
|
|
|
|
while (fgets(buf, 256, in)) {
|
2003-04-01 03:28:37 +00:00
|
|
|
if (match_tag(buf, "<cpu_benchmarks>"));
|
|
|
|
else if (match_tag(buf, "</cpu_benchmarks>")) return 0;
|
2002-12-09 23:51:55 +00:00
|
|
|
else if (parse_double(buf, "<p_fpops>", p_fpops)) continue;
|
|
|
|
else if (parse_double(buf, "<p_iops>", p_iops)) continue;
|
|
|
|
else if (parse_double(buf, "<p_membw>", p_membw)) continue;
|
2003-07-01 23:16:53 +00:00
|
|
|
else if (parse_int(buf, "<p_fpop_err>", p_fpop_err)) continue;
|
|
|
|
else if (parse_int(buf, "<p_iop_err>", p_iop_err)) continue;
|
|
|
|
else if (parse_int(buf, "<p_membw_err>", p_membw_err)) continue;
|
2002-12-09 23:51:55 +00:00
|
|
|
else if (parse_double(buf, "<p_calculated>", p_calculated)) continue;
|
|
|
|
else if (parse_double(buf, "<m_cache>", m_cache)) continue;
|
2003-07-03 05:01:29 +00:00
|
|
|
else msg_printf(NULL, MSG_ERROR, "HOST_INFO::parse(): unrecognized: %s\n", buf);
|
2002-12-09 23:51:55 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-04-01 03:28:37 +00:00
|
|
|
int HOST_INFO::write_cpu_benchmarks(FILE* out) {
|
2002-12-09 23:51:55 +00:00
|
|
|
fprintf(out,
|
2003-04-01 03:28:37 +00:00
|
|
|
"<cpu_benchmarks>\n"
|
2002-12-09 23:51:55 +00:00
|
|
|
" <p_fpops>%f</p_fpops>\n"
|
|
|
|
" <p_iops>%f</p_iops>\n"
|
|
|
|
" <p_membw>%f</p_membw>\n"
|
2003-07-01 23:16:53 +00:00
|
|
|
" <p_fpop_err>%d</p_fpop_err>\n"
|
|
|
|
" <p_iop_err>%d</p_iop_err>\n"
|
|
|
|
" <p_membw_err>%d</p_membw_err>\n"
|
2002-12-09 23:51:55 +00:00
|
|
|
" <p_calculated>%f</p_calculated>\n"
|
|
|
|
" <m_cache>%f</m_cache>\n"
|
2003-04-01 03:28:37 +00:00
|
|
|
"</cpu_benchmarks>\n",
|
2002-12-09 23:51:55 +00:00
|
|
|
p_fpops,
|
|
|
|
p_iops,
|
|
|
|
p_membw,
|
2003-07-01 23:16:53 +00:00
|
|
|
p_fpop_err,
|
|
|
|
p_iop_err,
|
|
|
|
p_membw_err,
|
2003-08-08 23:41:36 +00:00
|
|
|
p_calculated,
|
2002-12-09 23:51:55 +00:00
|
|
|
m_cache
|
|
|
|
);
|
|
|
|
return 0;
|
|
|
|
}
|
2002-10-28 19:04:13 +00:00
|
|
|
|
|
|
|
// Returns the domain of the local host
|
|
|
|
//
|
2003-02-24 21:25:16 +00:00
|
|
|
int get_local_domain_name(char* p, int len) {
|
2002-10-28 19:04:13 +00:00
|
|
|
char buf[256];
|
|
|
|
|
2003-03-08 23:48:05 +00:00
|
|
|
if (gethostname(buf, 256)) return -1;
|
2002-10-28 19:04:13 +00:00
|
|
|
struct hostent* he = gethostbyname(buf);
|
2002-11-19 22:57:05 +00:00
|
|
|
if (!he) return -1;
|
2003-03-06 00:42:18 +00:00
|
|
|
safe_strncpy(p, he->h_name, len);
|
2002-10-28 19:04:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the name of the local host
|
|
|
|
//
|
2003-03-08 23:48:05 +00:00
|
|
|
int get_local_ip_addr_str(char* p, int len) {
|
2003-03-19 01:15:46 +00:00
|
|
|
strcpy(p, "");
|
2002-12-05 23:32:25 +00:00
|
|
|
#if HAVE_NETDB_H || _WIN32
|
|
|
|
char buf[256];
|
2002-10-28 19:04:13 +00:00
|
|
|
struct in_addr addr;
|
2002-12-06 08:37:21 +00:00
|
|
|
if (gethostname(buf, 256)) {
|
|
|
|
printf("gethostname() didn't return name\n");
|
2002-12-05 21:30:39 +00:00
|
|
|
return -1;
|
2002-12-06 08:37:21 +00:00
|
|
|
}
|
2002-10-28 19:04:13 +00:00
|
|
|
struct hostent* he = gethostbyname(buf);
|
2002-12-06 08:37:21 +00:00
|
|
|
if (!he || !he->h_addr_list[0]) {
|
|
|
|
printf("gethostbyname() didn't return any IP addresses\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2002-10-28 19:04:13 +00:00
|
|
|
memcpy(&addr, he->h_addr_list[0], sizeof(addr));
|
2003-03-08 23:48:05 +00:00
|
|
|
safe_strncpy(p, inet_ntoa(addr), len);
|
2002-10-28 19:04:13 +00:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gets the ip address of the local host
|
|
|
|
//
|
|
|
|
int get_local_ip_addr(int& p) {
|
|
|
|
p = 0;
|
|
|
|
|
2002-12-05 23:32:25 +00:00
|
|
|
#if HAVE_NETDB_H || _WIN32
|
|
|
|
char buf[256];
|
2002-10-28 19:04:13 +00:00
|
|
|
struct in_addr addr;
|
2002-12-05 23:32:25 +00:00
|
|
|
if (gethostname(buf, 256))
|
2002-12-05 21:30:39 +00:00
|
|
|
return -1;
|
2002-10-28 19:04:13 +00:00
|
|
|
struct hostent* he = gethostbyname(buf);
|
2002-12-05 21:30:39 +00:00
|
|
|
if (!he) return -1;
|
2002-10-28 19:04:13 +00:00
|
|
|
memcpy(&addr, he->h_addr_list[0], sizeof(addr));
|
|
|
|
p = addr.s_addr;
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|