From 1f0642848394f4873893207325d91c79007d2312 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivano@gnu.org>
Date: Sat, 6 Aug 2011 12:38:42 +0200
Subject: [PATCH] Introduce `show_all_dns_entries'.

---
 NEWS          | 3 +++
 doc/ChangeLog | 2 ++
 doc/wget.texi | 4 ++++
 src/ChangeLog | 5 +++++
 src/host.c    | 8 ++++++--
 src/init.c    | 1 +
 src/options.h | 2 ++
 7 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 4d5e31b2..123b63c5 100644
--- a/NEWS
+++ b/NEWS
@@ -65,6 +65,9 @@ Please send GNU Wget bug reports to <bug-wget@gnu.org>.
 
 ** Do not attempt to remove the file if it is not in the accept rules but
    it is the output destination file.
+
+** Introduce `show_all_dns_entries' to print all IP addresses corresponding to
+   a DNS name when it is resolved.
 
 * Changes in Wget 1.12
 
diff --git a/doc/ChangeLog b/doc/ChangeLog
index 7b59c341..5ce40d5c 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -1,5 +1,7 @@
 2011-08-06  Giuseppe Scrivano  <gscrivano@gnu.org>
 
+	* wget.texi (Wgetrc Commands): Document show_all_dns_entries.
+
 	* Makefile.am (wget.pod): Pass the VERSION value to texi2pod.
 
 	* texi2pod.pl: Update from GCC.
diff --git a/doc/wget.texi b/doc/wget.texi
index 7c2a69dd..87b8f2de 100644
--- a/doc/wget.texi
+++ b/doc/wget.texi
@@ -3171,6 +3171,10 @@ as @samp{--secure-protocol=@var{string}}.
 Choose whether or not to print the @sc{http} and @sc{ftp} server
 responses---the same as @samp{-S}.
 
+@item show_all_dns_entries = on/off
+When a DNS name is resolved, show all the IP addresses, not just the first
+three.
+
 @item span_hosts = on/off
 Same as @samp{-H}.
 
diff --git a/src/ChangeLog b/src/ChangeLog
index b998e98f..c96da022 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,10 @@
 2011-08-06  Giuseppe Scrivano  <gscrivano@gnu.org>
 
+	* host.c (lookup_host): If `showalldnsentries' is used then print all
+	the IP corresponding to a DNS entry.
+	* init.c (commands): Add `showalldnsentries'.
+	Suggested by: Witold Baryluk <baryluk@smp.if.uj.edu.pl>
+
 	* http.c (gethttp): Add the Cache-Control HTTP header when --no-cache
 	is specified.
 	Reported by: Коренберг Марк <socketpair@gmail.com>.
diff --git a/src/host.c b/src/host.c
index 34dc7084..505f706c 100644
--- a/src/host.c
+++ b/src/host.c
@@ -822,11 +822,15 @@ lookup_host (const char *host, int flags)
 #endif /* not ENABLE_IPV6 */
 
   /* Print the addresses determined by DNS lookup, but no more than
-     three.  */
+     three if show_all_dns_entries is not specified.  */
   if (!silent && !numeric_address)
     {
       int i;
-      int printmax = al->count <= 3 ? al->count : 3;
+      int printmax = al->count;
+
+      if (! opt.show_all_dns_entries)
+        printmax = 3;
+
       for (i = 0; i < printmax; i++)
         {
           logputs (LOG_VERBOSE, print_address (al->addresses + i));
diff --git a/src/init.c b/src/init.c
index 17f9f9e6..8f44cdb4 100644
--- a/src/init.c
+++ b/src/init.c
@@ -247,6 +247,7 @@ static const struct {
   { "secureprotocol",   &opt.secure_protocol,   cmd_spec_secure_protocol },
 #endif
   { "serverresponse",   &opt.server_response,   cmd_boolean },
+  { "showalldnsentries", &opt.show_all_dns_entries, cmd_boolean },
   { "spanhosts",        &opt.spanhost,          cmd_boolean },
   { "spider",           &opt.spider,            cmd_boolean },
   { "strictcomments",   &opt.strict_comments,   cmd_boolean },
diff --git a/src/options.h b/src/options.h
index 05e5894d..252bf81d 100644
--- a/src/options.h
+++ b/src/options.h
@@ -253,6 +253,8 @@ struct options
   bool useservertimestamps;  	/* Update downloaded files' timestamps to
 				   match those on server? */
 
+  bool show_all_dns_entries; /* Show all the DNS entries when resolving a
+                                name. */
 };
 
 extern struct options opt;