152ae03
diff --git a/src/dns.c b/src/dns.c
152ae03
index a81823715d776499..30e0d1f639824f10 100644
152ae03
--- a/src/dns.c
152ae03
+++ b/src/dns.c
152ae03
@@ -102,6 +102,8 @@ lookup_host_saddr(struct sockaddr_in *res, const char *host, int port)
2618343
 
2618343
 
2618343
 #ifdef HAVE_GETADDRINFO
152ae03
+extern int force_ipv4;
152ae03
+extern int force_ipv6;
2618343
 /*
2618343
  *  This function looks up a hostname or IP number using the newer
2618343
  *  getaddrinfo() system call.
152ae03
@@ -118,6 +120,10 @@ lookup_host_addrinfo(struct addrinfo **res, const char *host, int port)
2618343
 
2618343
   memset(&hints, 0, sizeof(hints));
2618343
   hints.ai_family = PF_UNSPEC;
2618343
+  if (force_ipv6)
2618343
+	hints.ai_family = PF_INET6;
2618343
+  if (force_ipv4)
2618343
+	hints.ai_family = PF_INET;
2618343
 
2618343
   hints.ai_socktype = SOCK_STREAM;
2618343
   if (port)
152ae03
diff --git a/src/init.c b/src/init.c
152ae03
index 55ae2ebbf95ca1a2..c0027e9179709f8a 100644
152ae03
--- a/src/init.c
152ae03
+++ b/src/init.c
2618343
@@ -45,6 +45,8 @@ static struct option long_options[] =
2618343
   {"config", 1, 0, 'c'},
2618343
   {"host", 1, 0, 'h'},
2618343
   {"port", 1, 0, 'p'},
2618343
+  {"force-ipv4", 0, 0, '4'},
2618343
+  {"force-ipv6", 0, 0, '6'},
2618343
   {"force-lookup", 0, 0, 'f'},
2618343
   {"disable-cache", 0, 0, 'd'},
2618343
   {"no-redirect", 0, 0, 'n'},
2618343
@@ -114,6 +116,12 @@ int enable_whoisservers;
2618343
 /* Timeout value for connect calls in seconds */
2618343
 int connect_timeout;
2618343
 
2618343
+/* Set to 1 to force ipv4 */
2618343
+int force_ipv4;
2618343
+
2618343
+/* Set to 1 to force ipv6 */
2618343
+int force_ipv6;
2618343
+
2618343
 void help_version(int onlyversion)
2618343
 {
2618343
   char *COPYRIGHT = _("Copyright (C) 1999-%d  Free Software Foundation, Inc.\n");
152ae03
@@ -144,6 +152,10 @@ redistribute it under the terms of the GNU General Public License.");
152ae03
 #ifndef NOCACHE
2618343
    printf(_("  -f, --force-lookup         force lookup even if the entry is cached\n\
2618343
   -d, --disable-cache        disable cache functions\n"));
152ae03
+#endif
2618343
+#ifdef HAVE_GETADDRINFO
2618343
+  printf(_("-4, --force-ipv4           force ipv4 address resolution for whois host\n"));
2618343
+  printf(_("-6, --force-ipv6           force ipv6 address resolution for whois host\n"));
152ae03
 #endif
2618343
    printf("\n\n%s\n", _("Report bugs to bug-jwhois@gnu.org"));
2618343
     }
2618343
@@ -170,10 +182,12 @@ parse_args(int *argc, char ***argv)
2618343
   rwhois_display = NULL;
2618343
   rwhois_limit = 0;
2618343
   enable_whoisservers = 1;
2618343
+  force_ipv4 = 0;
2618343
+  force_ipv6 = 0;
2618343
 
2618343
   while (1)
2618343
     {
2618343
-      optch = getopt_long(*argc, *argv, "rainsvfdc:h:p:", long_options, &option_index);
2618343
+      optch = getopt_long(*argc, *argv, "rainsvfd46c:h:p:", long_options, &option_index);
2618343
       if (optch == EOF)
2618343
 	break;
2618343
       
2618343
@@ -252,6 +266,12 @@ parse_args(int *argc, char ***argv)
2618343
 	  gport = atoi(optarg);
2618343
 #endif
2618343
 	  break;
2618343
+        case '4':
2618343
+	  force_ipv4 = 1;
2618343
+	  break;
2618343
+        case '6':
2618343
+	  force_ipv6 = 1;
2618343
+	  break;
2618343
 	}
2618343
     }
2618343