From f6e4923ed38d5914dd714bc116ea72bdc4186919 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 17 Jun 2004 17:00:14 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=3633 --- checkin_notes | 18 ++++++++++ client/gui_rpc_server.C | 2 +- client/hostinfo_network.C | 72 ++++++++++++++++++++++++------------- client/hostinfo_network.h | 5 +-- client/hostinfo_unix.C | 6 ++-- client/win/hostinfo_win.cpp | 5 +-- doc/backend_state.php | 2 -- doc/client_unix.php | 4 ++- doc/gui_rpc.php | 36 +++++++++++++++---- doc/links.php | 13 ++++--- py/Boinc/database.py | 1 + 11 files changed, 115 insertions(+), 49 deletions(-) diff --git a/checkin_notes b/checkin_notes index 0fce5b4eaf..5f147e7666 100755 --- a/checkin_notes +++ b/checkin_notes @@ -13836,3 +13836,21 @@ David 16 June 2004 Rom June 16 2004 - Tag for 3.10 release, all platforms boinc_core_release_3_10 + +David 17 June 2004 + - Change the way we get local host's domain name on UNIX: + instead of gethostbyname() + (which has nightmarish linkage problems that no one quite understands) + use "ping", which we assume exists on all UNIX systems, + and parse its output + - Allow Python scripts to access remote databases + (courtesy of Carl C.) + + client/ + gui_rpc_server.C + hostinfo_network.C,h + hostinfo_unix.C + win/ + hostinfo_win.cpp + py/Boinc/ + database.py diff --git a/client/gui_rpc_server.C b/client/gui_rpc_server.C index ceb69b8ad8..b518a9fe6e 100644 --- a/client/gui_rpc_server.C +++ b/client/gui_rpc_server.C @@ -199,7 +199,7 @@ void handle_get_messages(char* buf, MIOFILE& fout) { iter++, j++ ) { MESSAGE_DESC* mdp = *iter; - if (seqno && mdp->seqno < seqno) break; + if (mdp->seqno <= seqno) break; fout.printf( "\n" " %d\n" diff --git a/client/hostinfo_network.C b/client/hostinfo_network.C index 276f04a627..a4e831969e 100644 --- a/client/hostinfo_network.C +++ b/client/hostinfo_network.C @@ -44,53 +44,75 @@ #include "util.h" #include "parse.h" +#include "file_names.h" #include "client_msgs.h" #include "error_numbers.h" #include "hostinfo.h" -// Returns the domain of the local host +// get domain name and IP address of this host // -int get_local_domain_name(char* p, int len) { +int get_local_network_info( + char* domain_name, int domlen, char* ip_addr, int iplen +) { +#ifdef _WIN32 char buf[256]; if (gethostname(buf, 256)) return ERR_GETHOSTBYNAME; struct hostent* he = gethostbyname(buf); if (!he) return ERR_GETHOSTBYNAME; - safe_strncpy(p, he->h_name, len); - return 0; -} + safe_strncpy(domain_name, he->h_name, domlen); -// Get the IP address of the local host -// -static int get_local_ip_addr(struct in_addr& addr) { -#if HAVE_NETDB_H || _WIN32 - char buf[256]; if (gethostname(buf, 256)) { msg_printf(NULL, MSG_ERROR, "get_local_ip_addr(): gethostname failed\n"); return ERR_GETHOSTNAME; } + + struct in_addr addr; struct hostent* he = gethostbyname(buf); if (!he || !he->h_addr_list[0]) { msg_printf(NULL, MSG_ERROR, "get_local_ip_addr(): gethostbyname failed\n"); return ERR_GETHOSTBYNAME; } memcpy(&addr, he->h_addr_list[0], sizeof(addr)); + + strcpy(ip_addr, ""); + safe_strncpy(ip_addr, inet_ntoa(addr), iplen); + return 0; +#else + +// gethostbyname() is a linkage nightmare on UNIX systems (go figure) +// so use a kludge instead: run ping and parse the output +// should be "PING domainname (ipaddr) ..." +// + char hostname[256]; + char buf[256]; + int retval; + + if (gethostname(hostname, 256)) return ERR_GETHOSTBYNAME; + sprintf(buf, "ping -c 1 %s > %s", hostname, TEMP_FILE_NAME); + retval = system(buf); + if (retval) return retval; + FILE* f = fopen(TEMP_FILE_NAME, "r"); + if (!f) return ERR_FOPEN; + fgets(buf, 256, f); + fclose(f); + char *p, *q; + p = strchr(buf, ' '); + if (!p) return ERR_NULL; + p++; + q = strchr(p, ' '); + if (!q) return ERR_NULL; + *q = 0; + safe_strncpy(domain_name, p, domlen); + q++; + p = strchr(q, '('); + if (!p) return ERR_NULL; + p++; + q = strchr(p, ')'); + if (!q) return ERR_NULL; + *q = 0; + safe_strncpy(ip_addr, p, iplen); return 0; -#elif - GET IP ADDR NOT IMPLEMENTED #endif } - -// Get the IP address as a string -// -int get_local_ip_addr_str(char* p, int len) { - int retval; - struct in_addr addr; - - strcpy(p, ""); - retval = get_local_ip_addr(addr); - if (retval) return retval; - safe_strncpy(p, inet_ntoa(addr), len); - return 0; -} diff --git a/client/hostinfo_network.h b/client/hostinfo_network.h index 4f5d8c1cf7..6fa895d35a 100644 --- a/client/hostinfo_network.h +++ b/client/hostinfo_network.h @@ -1,4 +1 @@ - -extern int get_local_domain_name(char* p, int len); -extern int get_local_ip_addr_str(char* p, int len); -extern int get_local_ip_addr(int& p); +extern int get_local_network_info(char* dom, int ,char* ip, int iplen); diff --git a/client/hostinfo_unix.C b/client/hostinfo_unix.C index 362270aa2f..ad7ccf2e49 100644 --- a/client/hostinfo_unix.C +++ b/client/hostinfo_unix.C @@ -374,8 +374,10 @@ int HOST_INFO::get_host_info() { #endif #endif - get_local_domain_name(domain_name, sizeof(domain_name)); - get_local_ip_addr_str(ip_addr, sizeof(ip_addr)); + get_local_network_info( + domain_name, sizeof(domain_name), ip_addr, sizeof(ip_addr) + ); + timezone = get_timezone(); #ifdef HAVE_SYS_UTSNAME_H struct utsname u; diff --git a/client/win/hostinfo_win.cpp b/client/win/hostinfo_win.cpp index 236aa5c849..60bd6ed228 100755 --- a/client/win/hostinfo_win.cpp +++ b/client/win/hostinfo_win.cpp @@ -318,8 +318,9 @@ int HOST_INFO::get_host_info() { WSAStartup(wVersionRequested, &wsdata); // Get host name/ip info - get_local_domain_name(domain_name, sizeof(domain_name)); - get_local_ip_addr_str(ip_addr, sizeof(ip_addr)); + get_local_network_info( + domain_name, sizeof(domain_name), ip_addr, sizeof(ip_addr) + ); // Close the WinSock dll WSACleanup(); diff --git a/doc/backend_state.php b/doc/backend_state.php index 5abce31684..e0a82b6b92 100644 --- a/doc/backend_state.php +++ b/doc/backend_state.php @@ -89,8 +89,6 @@ list_item("error_mask", list_end(); echo " - - Workunit invariants: