This patch adds a forward lookup of any hostnames listed in the
"hosts allow" or "hosts deny" daemon config options.  Based on
a patch by Paul Williamson.

To use this patch, run these commands for a successful build:

    patch -p1 <patches/daemon-forward-lookup.diff
    ./configure                         (optional if already run)
    make

diff --git a/access.c b/access.c
index 9a023de..ad1cdb1 100644
--- a/access.c
+++ b/access.c
@@ -210,6 +210,38 @@ static int match_address(const char *addr, const char *tok)
 	return ret;
 }
 
+static int match_hostlookup(const char *addr, const char *tok)
+{
+	struct hostent *hp = NULL;
+	unsigned int i, len;
+	const char *p;
+
+	if ((p = strchr(tok,'/')) != NULL)
+		len = p - tok;
+	else
+		len = strlen(tok);
+
+	/* Fail quietly (hp left NULL) if tok is an address, not a hostname. */
+#ifdef INET6
+	if (strcspn(tok, ":/") != len) {
+		;
+	} else
+#endif
+	if (strspn(tok, ".0123456789") != len)
+		hp = gethostbyname(tok);
+
+	if (!hp)
+		return 0;
+
+	for (i = 0; hp->h_addr_list[i] != NULL; i++) {
+		tok = inet_ntoa(*(struct in_addr*)(hp->h_addr_list[i]));
+		if (match_address(addr, tok))
+			return 1;
+	}
+
+	return 0;
+}
+
 static int access_match(const char *list, const char *addr, const char *host)
 {
 	char *tok;
@@ -221,7 +253,7 @@ static int access_match(const char *list, const char *addr, const char *host)
 	strlower(list2);
 
 	for (tok = strtok(list2, " ,\t"); tok; tok = strtok(NULL, " ,\t")) {
-		if (match_hostname(host, tok) || match_address(addr, tok)) {
+		if (match_hostname(host, tok) || match_address(addr, tok) || match_hostlookup(addr, tok)) {
 			free(list2);
 			return 1;
 		}
