~ubuntu-branches/ubuntu/precise/boinc/precise

« back to all changes in this revision

Viewing changes to client/hostinfo_network.cpp

Tags: 6.12.8+dfsg-1
* New upstream release.
* Simplified debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
// You should have received a copy of the GNU Lesser General Public License
16
16
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
17
17
 
 
18
#include "cpp.h"
 
19
 
18
20
#ifdef _WIN32
19
21
#include "boinc_win.h"
20
 
 
21
22
#else 
22
 
 
23
23
#include "config.h"
24
24
#include <cstdio>
25
25
#include <cstring>
26
 
 
27
26
#if HAVE_UNISTD_H
28
27
#include <unistd.h>
29
28
#endif
46
45
#endif
47
46
 
48
47
#include "str_util.h"
 
48
#include "str_replace.h"
49
49
#include "parse.h"
50
50
#include "util.h"
51
51
#include "file_names.h"
58
58
// get domain name and IP address of this host
59
59
//
60
60
int HOST_INFO::get_local_network_info() {
61
 
    struct in_addr addr;
62
 
    struct hostent* he;
 
61
    struct sockaddr_storage s;
63
62
    
64
63
    strcpy(domain_name, "");
65
64
    strcpy(ip_addr, "");
67
66
    // it seems like we should use getdomainname() instead of gethostname(),
68
67
    // but on FC6 it returns "(none)".
69
68
    //
70
 
    if (gethostname(domain_name, 256)) return ERR_GETHOSTBYNAME;
71
 
    he = gethostbyname(domain_name);
72
 
    if (!he || !he->h_addr_list[0]) {
73
 
        //msg_printf(NULL, MSG_ERROR, "gethostbyname (%s) failed", domain_name);
 
69
    if (gethostname(domain_name, 256)) {
74
70
        return ERR_GETHOSTBYNAME;
75
71
    }
76
 
    memcpy(&addr, he->h_addr_list[0], sizeof(addr));
77
 
    strlcpy(ip_addr, inet_ntoa(addr), sizeof(ip_addr));
 
72
    int retval = resolve_hostname(domain_name, s);
 
73
    if (retval) return retval;
 
74
#ifdef _WIN32
 
75
    sockaddr_in* sin = (sockaddr_in*)&s;
 
76
    strlcpy(ip_addr, inet_ntoa(sin->sin_addr), sizeof(ip_addr));
 
77
#else
 
78
    if (s.ss_family == AF_INET) {
 
79
        sockaddr_in* sin = (sockaddr_in*)&s;
 
80
        inet_ntop(AF_INET, (void*)(&sin->sin_addr), ip_addr, 256);
 
81
    } else {
 
82
        sockaddr_in6* sin = (sockaddr_in6*)&s;
 
83
        inet_ntop(AF_INET6, (void*)(&sin->sin6_addr), ip_addr, 256);
 
84
    }
 
85
#endif
78
86
    return 0;
79
87
}
80
88
 
93
101
// Should be unique across hosts with very high probability
94
102
//
95
103
void HOST_INFO::generate_host_cpid() {
96
 
#if defined(__linux__) || defined(_WIN32) || defined(__APPLE__ )
 
104
// Assume that get_mac_addresses can be ported to any unix system.
 
105
// If not, it can return false.
 
106
//
 
107
#if defined(__linux__) || defined(_WIN32) || defined(__APPLE__ ) || defined(__unix)
97
108
    char buffer[8192] = "";
98
109
        // must be big enough to accommodate aa:bb:cc:dd:ee:ff
99
110
        // times the number of network interfaces,
113
124
#endif
114
125
}
115
126
 
116
 
 
117
 
const char *BOINC_RCSID_9275b20aa5 = "$Id: hostinfo_network.cpp 16433 2008-11-05 20:27:04Z davea $";