Blob Blame History Raw
diff -Npru jwhois-4.0.orig/src/dns.c jwhois-4.0/src/dns.c
--- jwhois-4.0.orig/src/dns.c	2007-06-26 08:58:38.000000000 +0200
+++ jwhois-4.0/src/dns.c	2018-03-03 14:35:48.680685322 +0100
@@ -102,6 +102,8 @@ lookup_host_saddr(struct sockaddr_in *re
 
 
 #ifdef HAVE_GETADDRINFO
+extern force_ipv4;
+extern force_ipv6;
 /*
  *  This function looks up a hostname or IP number using the newer
  *  getaddrinfo() system call.
@@ -118,6 +120,10 @@ lookup_host_addrinfo(struct addrinfo **r
 
   memset(&hints, 0, sizeof(hints));
   hints.ai_family = PF_UNSPEC;
+  if (force_ipv6)
+	hints.ai_family = PF_INET6;
+  if (force_ipv4)
+	hints.ai_family = PF_INET;
 
   hints.ai_socktype = SOCK_STREAM;
   if (port)
diff -Npru jwhois-4.0.orig/src/init.c jwhois-4.0/src/init.c
--- jwhois-4.0.orig/src/init.c	2018-03-03 12:24:49.368945237 +0100
+++ jwhois-4.0/src/init.c	2018-03-03 14:49:38.119217799 +0100
@@ -45,6 +45,8 @@ static struct option long_options[] =
   {"config", 1, 0, 'c'},
   {"host", 1, 0, 'h'},
   {"port", 1, 0, 'p'},
+  {"force-ipv4", 0, 0, '4'},
+  {"force-ipv6", 0, 0, '6'},
   {"force-lookup", 0, 0, 'f'},
   {"disable-cache", 0, 0, 'd'},
   {"no-redirect", 0, 0, 'n'},
@@ -114,6 +116,12 @@ int enable_whoisservers;
 /* Timeout value for connect calls in seconds */
 int connect_timeout;
 
+/* Set to 1 to force ipv4 */
+int force_ipv4;
+
+/* Set to 1 to force ipv6 */
+int force_ipv6;
+
 void help_version(int onlyversion)
 {
   char *COPYRIGHT = _("Copyright (C) 1999-%d  Free Software Foundation, Inc.\n");
@@ -145,6 +153,10 @@ redistribute it under the terms of the G
    printf(_("  -f, --force-lookup         force lookup even if the entry is cached\n\
   -d, --disable-cache        disable cache functions\n"));
 #endif
+#ifdef HAVE_GETADDRINFO
+  printf(_("-4, --force-ipv4           force ipv4 address resolution for whois host\n"));
+  printf(_("-6, --force-ipv6           force ipv6 address resolution for whois host\n"));
+#endif
    printf("\n\n%s\n", _("Report bugs to bug-jwhois@gnu.org"));
     }
 }
@@ -170,10 +182,12 @@ parse_args(int *argc, char ***argv)
   rwhois_display = NULL;
   rwhois_limit = 0;
   enable_whoisservers = 1;
+  force_ipv4 = 0;
+  force_ipv6 = 0;
 
   while (1)
     {
-      optch = getopt_long(*argc, *argv, "rainsvfdc:h:p:", long_options, &option_index);
+      optch = getopt_long(*argc, *argv, "rainsvfd46c:h:p:", long_options, &option_index);
       if (optch == EOF)
 	break;
       
@@ -252,6 +266,12 @@ parse_args(int *argc, char ***argv)
 	  gport = atoi(optarg);
 #endif
 	  break;
+        case '4':
+	  force_ipv4 = 1;
+	  break;
+        case '6':
+	  force_ipv6 = 1;
+	  break;
 	}
     }