- Log_Resolver( LOG_WARNING, "Can't resolve address \"%s\"!", inet_ntoa( Addr->sin_addr ));
-#endif
- strlcpy( hostname, inet_ntoa( Addr->sin_addr ), sizeof( hostname ));
+ (void) identsock;
+ (void) resolved_addr;
+#endif
+}
+
+
+/**
+ * perform reverse DNS lookup and put result string into resbuf.
+ * If no hostname could be obtained, this function stores the string representation of
+ * the IP address in resbuf and returns false.
+ * @param IpAddr ip address to resolve
+ * @param resbuf result buffer to store DNS name/string representation of ip address
+ * @param reslen size of result buffer (must be >= NGT_INET_ADDRSTRLEN)
+ * @return true if reverse lookup successful, false otherwise
+ */
+static bool
+ReverseLookup(const ng_ipaddr_t *IpAddr, char *resbuf, size_t reslen)
+{
+ char tmp_ip_str[NG_INET_ADDRSTRLEN];
+ const char *errmsg;
+#ifdef HAVE_GETNAMEINFO
+ static const char funcname[]="getnameinfo";
+ int res;
+
+ *resbuf = 0;
+
+ res = getnameinfo((struct sockaddr *) IpAddr, ng_ipaddr_salen(IpAddr),
+ resbuf, (socklen_t)reslen, NULL, 0, NI_NAMEREQD);
+ if (res == 0)
+ return true;
+
+ if (res == EAI_SYSTEM)
+ errmsg = strerror(errno);
+ else
+ 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";