+ errmsg = gai_strerror(res);
+#else
+ const struct sockaddr_in *Addr = (const struct sockaddr_in *) IpAddr;
+ struct hostent *h;
+ static const char funcname[]="gethostbyaddr";
+
+ h = gethostbyaddr((char *)&Addr->sin_addr, sizeof(Addr->sin_addr), AF_INET);
+ if (h) {
+ if (strlcpy(resbuf, h->h_name, reslen) < reslen)
+ return true;
+ errmsg = "hostname too long";
+ } else {
+# ifdef h_errno
+ errmsg = Get_Error(h_errno);
+# else
+ errmsg = "unknown error";
+# endif /* h_errno */
+ }
+#endif /* HAVE_GETNAMEINFO */
+
+ assert(errmsg);
+ assert(reslen >= NG_INET_ADDRSTRLEN);
+ ng_ipaddr_tostr_r(IpAddr, tmp_ip_str);
+
+ Log_Resolver(LOG_WARNING, "%s: Can't resolve address \"%s\": %s",
+ funcname, tmp_ip_str, errmsg);
+ strlcpy(resbuf, tmp_ip_str, reslen);
+ return false;
+}
+
+
+/**
+ * perform DNS lookup of given host name and fill IpAddr with a list of
+ * ip addresses associated with that name.
+ * ip addresses found are stored in the "array *IpAddr" argument (type ng_ipaddr_t)
+ * @param hostname The domain name to look up.
+ * @param IpAddr pointer to empty and initialized array to store results
+ * @return true if lookup successful, false if domain name not found
+ */
+static bool
+ForwardLookup(const char *hostname, array *IpAddr)
+{
+ ng_ipaddr_t addr;
+
+#ifdef HAVE_GETADDRINFO
+ int res;
+ struct addrinfo *a, *ai_results;
+ static struct addrinfo hints;
+
+#ifndef WANT_IPV6
+ hints.ai_family = AF_INET;
+#endif
+#ifdef AI_ADDRCONFIG /* glibc has this, but not e.g. netbsd 4.0 */
+ hints.ai_flags = AI_ADDRCONFIG;
+#endif
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = IPPROTO_TCP;
+
+#ifdef WANT_IPV6
+ assert(Conf_ConnectIPv6 || Conf_ConnectIPv4);
+
+ if (!Conf_ConnectIPv6)
+ hints.ai_family = AF_INET;
+ if (!Conf_ConnectIPv4)
+ hints.ai_family = AF_INET6;
+#endif
+ memset(&addr, 0, sizeof(addr));
+
+ res = getaddrinfo(hostname, NULL, &hints, &ai_results);
+ switch (res) {
+ case 0: break;
+ case EAI_SYSTEM:
+ Log_Resolver(LOG_WARNING, "Can't resolve \"%s\": %s", hostname, strerror(errno));
+ return false;
+ default:
+ Log_Resolver(LOG_WARNING, "Can't resolve \"%s\": %s", hostname, gai_strerror(res));
+ return false;
+ }
+
+ for (a = ai_results; a != NULL; a = a->ai_next) {
+ assert(a->ai_addrlen <= sizeof(addr));
+
+ if (a->ai_addrlen > sizeof(addr))
+ continue;
+
+ memcpy(&addr, a->ai_addr, a->ai_addrlen);
+
+ if (!array_catb(IpAddr, (char *)&addr, sizeof(addr)))
+ break;
+ }
+
+ freeaddrinfo(ai_results);
+ return a == NULL;
+#else
+ struct hostent *h = gethostbyname(hostname);
+
+ if (!h) {