67
66
// it seems like we should use getdomainname() instead of gethostname(),
68
67
// but on FC6 it returns "(none)".
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;
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;
75
sockaddr_in* sin = (sockaddr_in*)&s;
76
strlcpy(ip_addr, inet_ntoa(sin->sin_addr), sizeof(ip_addr));
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);
82
sockaddr_in6* sin = (sockaddr_in6*)&s;
83
inet_ntop(AF_INET6, (void*)(&sin->sin6_addr), ip_addr, 256);
93
101
// Should be unique across hosts with very high probability
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.
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,