2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2004-06-16 19:21:11 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation;
|
|
|
|
// either version 2.1 of the License, or (at your option) any later version.
|
2004-06-16 19:21:11 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2004-06-16 19:21:11 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2004-06-16 19:21:11 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2004-06-16 23:16:08 +00:00
|
|
|
#include "boinc_win.h"
|
2004-06-16 19:21:11 +00:00
|
|
|
|
2005-12-16 03:45:01 +00:00
|
|
|
#else
|
|
|
|
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
2004-06-16 19:21:11 +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
|
|
|
|
#endif
|
|
|
|
|
2006-04-08 11:00:45 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
#endif
|
|
|
|
|
2007-02-21 16:26:51 +00:00
|
|
|
#include "str_util.h"
|
2004-06-16 19:21:11 +00:00
|
|
|
#include "parse.h"
|
2004-06-17 17:00:14 +00:00
|
|
|
#include "file_names.h"
|
2004-06-16 19:21:11 +00:00
|
|
|
#include "client_msgs.h"
|
|
|
|
#include "error_numbers.h"
|
|
|
|
|
|
|
|
#include "hostinfo.h"
|
|
|
|
|
2004-06-17 17:00:14 +00:00
|
|
|
// get domain name and IP address of this host
|
2004-06-16 19:21:11 +00:00
|
|
|
//
|
2006-06-23 20:41:47 +00:00
|
|
|
int HOST_INFO::get_local_network_info() {
|
2004-06-17 17:09:03 +00:00
|
|
|
struct in_addr addr;
|
2006-04-08 11:00:45 +00:00
|
|
|
struct hostent* he;
|
|
|
|
|
2007-08-11 03:34:38 +00:00
|
|
|
strcpy(domain_name, "");
|
|
|
|
strcpy(ip_addr, "");
|
|
|
|
if (gethostname(domain_name, 256)) return ERR_GETHOSTBYNAME;
|
|
|
|
he = gethostbyname(domain_name);
|
2004-06-16 19:21:11 +00:00
|
|
|
if (!he || !he->h_addr_list[0]) {
|
2007-08-14 02:38:38 +00:00
|
|
|
//msg_printf(NULL, MSG_ERROR, "gethostbyname (%s) failed", domain_name);
|
2004-06-16 19:21:11 +00:00
|
|
|
return ERR_GETHOSTBYNAME;
|
|
|
|
}
|
|
|
|
memcpy(&addr, he->h_addr_list[0], sizeof(addr));
|
2006-06-23 20:41:47 +00:00
|
|
|
strlcpy(ip_addr, inet_ntoa(addr), sizeof(ip_addr));
|
2004-06-16 19:21:11 +00:00
|
|
|
return 0;
|
2004-06-17 17:54:05 +00:00
|
|
|
}
|
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_9275b20aa5 = "$Id$";
|