]> sjero.net Git - wget/commitdiff
[svn] Don't auto-set opt.ipv4_only on systems without IPv6 sockets.
authorhniksic <devnull@localhost>
Mon, 17 Nov 2003 12:59:54 +0000 (04:59 -0800)
committerhniksic <devnull@localhost>
Mon, 17 Nov 2003 12:59:54 +0000 (04:59 -0800)
src/ChangeLog
src/connect.c
src/connect.h
src/host.c
src/init.c
src/main.c

index fad417901edeb5529a09b8f70c54ed822ec08bbd..ed6faf5fe4a591323352a059d7545b38e1fda5aa 100644 (file)
@@ -1,3 +1,11 @@
+2003-11-17  Hrvoje Niksic  <hniksic@xemacs.org>
+
+       * host.c (lookup_host): Check for the ability to create IPv6
+       sockets here.
+
+       * init.c (defaults): Don't auto-set --inet4-only on IPv6-less
+       systems.
+
 2003-11-16  Hrvoje Niksic  <hniksic@xemacs.org>
 
        * main.c (print_help): Fix typo in `-O' help message.  Fix docs of
index d309b27264a759c6f450e8958aaf90e29acdd963..4b09c2da9739c05b973b40457831a3841ababf3d 100644 (file)
@@ -614,6 +614,24 @@ retryable_socket_connect_error (int err)
   return 1;
 }
 
+int
+socket_has_inet6 (void)
+{
+  static int supported = -1;
+  if (supported == -1)
+    {
+      int sock = socket (AF_INET6, SOCK_STREAM, 0);
+      if (sock < 0)
+       supported = 0;
+      else
+       {
+         xclose (sock);
+         supported = 1;
+       }
+    }
+  return supported;
+}
+
 #ifdef HAVE_SELECT
 
 /* Wait for file descriptor FD to be readable or writable or both,
index 0a341aa9d5333dc1ebbae062360a4823404a50cf..06fdf36809edb8db7212cf7f6e4449ea6d70ce83 100644 (file)
@@ -65,6 +65,7 @@ enum {
 };
 int select_fd PARAMS ((int, double, int));
 int test_socket_open PARAMS ((int));
+int socket_has_inet6 PARAMS ((void));
 
 typedef int (*xreader_t) PARAMS ((int, char *, int, void *));
 typedef int (*xwriter_t) PARAMS ((int, char *, int, void *));
index b77c1170bd0835e48caf46d58951c1d5818c8379..008c02a2b9094e988e03110570f68b4378318932 100644 (file)
@@ -67,6 +67,7 @@ so, delete this exception statement from your version.  */
 #include "host.h"
 #include "url.h"
 #include "hash.h"
+#include "connect.h"           /* for socket_has_inet6 */
 
 #ifndef errno
 extern int errno;
@@ -575,17 +576,20 @@ lookup_host (const char *host, int flags)
 
     xzero (hints);
     hints.ai_socktype = SOCK_STREAM;
-    if (opt.ipv4_only && !opt.ipv6_only)
+    if (opt.ipv4_only)
       hints.ai_family = AF_INET;
-    else if (opt.ipv6_only && !opt.ipv4_only)
+    else if (opt.ipv6_only)
       hints.ai_family = AF_INET6;
     else
       {
        hints.ai_family = AF_UNSPEC;
 #ifdef HAVE_GETADDRINFO_AI_ADDRCONFIG
-       /* Use AI_ADDRCONFIG if available and if specific family isn't
-          explicitly requested.  See init.c:defaults().  */
        hints.ai_flags |= AI_ADDRCONFIG;
+#else
+       /* On systems without AI_ADDRCONFIG, emulate it by manually
+          checking whether the system supports IPv6 sockets and.  */
+       if (!socket_has_inet6 ())
+         hints.ai_family = AF_INET;
 #endif
       }
     if (flags & LH_BIND)
index 220c8c00f8d7d998dafd5c50b4f9fdbd46b99e29..f97ba3a9169c75eae3a351a7b8f2306b68525029 100644 (file)
@@ -304,30 +304,6 @@ defaults (void)
   opt.restrict_files_os = restrict_windows;
 #endif
   opt.restrict_files_ctrl = 1;
-
-#ifdef ENABLE_IPV6
-# ifndef HAVE_GETADDRINFO_AI_ADDRCONFIG
-  /* If IPv6 is enabled, but AI_ADDRCONFIG is missing, check whether
-     we can create AF_INET6 sockets.  If we can't, turn on the
-     --inet4-only setting.  This is necessary because on some systems
-     (e.g. RHL 9) getaddrinfo resolves AAAA records, but socket()
-     can't even create an AF_INET6 socket, let alone connect to IPv6
-     hosts.  To avoid "address family not supported" error messages,
-     we set ipv4_only.
-
-     We do it as early as here, so that the user can revert the
-     settingn using --no-inet4-only, in case he wants to see the error
-     messages, for whatever reason.  */
-  {
-    int sock = socket (AF_INET6, SOCK_STREAM, 0);
-    if (sock < 0)
-      opt.ipv4_only = -1;      /* special value -1 because the option
-                                  was not specified by the user.  */
-    else
-      close (sock);
-  }
-# endif /* not HAVE_GETADDRINFO_AI_ADDRCONFIG */
-#endif /* ENABLE_IPV6 */
 }
 \f
 /* Return the user's home directory (strdup-ed), or NULL if none is
index 1998fde9eadd227267b716b304477a02af2fb4e2..0fb65f3b655d2f4f2ab3852661d88d0770b07b57 100644 (file)
@@ -547,7 +547,7 @@ HTTPS (SSL) options:\n"),
     N_("\
 FTP options:\n"),
     N_("\
-  -nr, --no-remove-listing  don't remove `.listing' files.\n"),
+       --no-remove-listing  don't remove `.listing' files.\n"),
     N_("\
        --no-glob            turn off FTP file name globbing.\n"),
     N_("\
@@ -809,12 +809,7 @@ Can't timestamp and not clobber old files at the same time.\n"));
     }
   if (opt.ipv4_only && opt.ipv6_only)
     {
-      if (opt.ipv4_only == -1)
-       /* ipv4_only was set automatically because the system doesn't
-          support IPv6.  */
-       printf (_("Cannot use --inet6-only on a system without IPv6 support.\n"));
-      else
-       printf (_("Cannot specify both --inet4-only and --inet6-only.\n"));
+      printf (_("Cannot specify both --inet4-only and --inet6-only.\n"));
       print_usage ();
       exit (1);
     }