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
|
|
|
|
|
2004-06-16 19:21:11 +00:00
|
|
|
#include "util.h"
|
|
|
|
#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-16 19:21:11 +00:00
|
|
|
char buf[256];
|
2004-06-17 17:09:03 +00:00
|
|
|
struct in_addr addr;
|
2006-04-08 11:00:45 +00:00
|
|
|
struct hostent* he;
|
|
|
|
|
2006-06-23 20:41:47 +00:00
|
|
|
if (gethostname(buf, 256)) return ERR_GETHOSTBYNAME;
|
2006-04-08 11:00:45 +00:00
|
|
|
he = gethostbyname(buf);
|
2004-06-16 19:21:11 +00:00
|
|
|
if (!he || !he->h_addr_list[0]) {
|
2006-06-23 20:41:47 +00:00
|
|
|
msg_printf(NULL, MSG_ERROR, "gethostbyname (%s) failed", buf);
|
2004-06-16 19:21:11 +00:00
|
|
|
return ERR_GETHOSTBYNAME;
|
|
|
|
}
|
2006-06-23 20:41:47 +00:00
|
|
|
strlcpy(domain_name, he->h_name, sizeof(domain_name));
|
2004-06-16 19:21:11 +00:00
|
|
|
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$";
|