diff -ur --speed-large-files zabbix-2.0.5.save/src/libs/zbxcomms/comms.c zabbix-2.0.5/src/libs/zbxcomms/comms.c --- zabbix-2.0.5.save/src/libs/zbxcomms/comms.c 2013-02-12 14:27:22.000000000 +0300 +++ zabbix-2.0.5/src/libs/zbxcomms/comms.c 2013-03-27 13:13:11.000000000 +0300 @@ -83,15 +83,19 @@ * Author: Alexei Vladishev * * * ******************************************************************************/ -#if defined(HAVE_IPV6) void zbx_gethost_by_ip(const char *ip, char *host, size_t hostlen) { struct addrinfo hints, *ai = NULL; + struct addrinfo *ai2 = NULL, *a; assert(ip); memset(&hints, 0, sizeof(hints)); +#if defined(HAVE_IPV6) hints.ai_family = PF_UNSPEC; +#else + hints.ai_family = PF_INET; +#endif if (0 != getaddrinfo(ip, NULL, &hints, &ai)) { @@ -104,33 +108,29 @@ host[0] = '\0'; goto out; } -out: - if (NULL != ai) - freeaddrinfo(ai); -} -#else -void zbx_gethost_by_ip(const char *ip, char *host, size_t hostlen) -{ - struct in_addr addr; - struct hostent *hst; - assert(ip); - - if (0 == inet_aton(ip, &addr)) + if (0 != getaddrinfo(host, NULL, &hints, &ai2)) { host[0] = '\0'; - return; + goto out; } - if (NULL == (hst = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET))) + for (a = ai2; a != NULL; a = a->ai_next) { - host[0] = '\0'; - return; + if (ai->ai_family != a->ai_family) continue; + if (ai->ai_addrlen != a->ai_addrlen) continue; + if (0 != memcmp(ai->ai_addr, a->ai_addr, ai->ai_addrlen)) continue; + goto out; } - zbx_strlcpy(host, hst->h_name, hostlen); + host[0] = '\0'; + +out: + if (NULL != ai) + freeaddrinfo(ai); + if (NULL != ai2) + freeaddrinfo(ai2); } -#endif /* HAVE_IPV6 */ #endif /* _WINDOWS */ /******************************************************************************