From 133d69ff24cc562b68fef463780f1858c4028d99 Mon Sep 17 00:00:00 2001 From: hniksic Date: Mon, 17 Nov 2003 04:59:54 -0800 Subject: [PATCH] [svn] Don't auto-set opt.ipv4_only on systems without IPv6 sockets. --- src/ChangeLog | 8 ++++++++ src/connect.c | 18 ++++++++++++++++++ src/connect.h | 1 + src/host.c | 12 ++++++++---- src/init.c | 24 ------------------------ src/main.c | 9 ++------- 6 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index fad41790..ed6faf5f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2003-11-17 Hrvoje Niksic + + * 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 * main.c (print_help): Fix typo in `-O' help message. Fix docs of diff --git a/src/connect.c b/src/connect.c index d309b272..4b09c2da 100644 --- a/src/connect.c +++ b/src/connect.c @@ -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, diff --git a/src/connect.h b/src/connect.h index 0a341aa9..06fdf368 100644 --- a/src/connect.h +++ b/src/connect.h @@ -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 *)); diff --git a/src/host.c b/src/host.c index b77c1170..008c02a2 100644 --- a/src/host.c +++ b/src/host.c @@ -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) diff --git a/src/init.c b/src/init.c index 220c8c00..f97ba3a9 100644 --- a/src/init.c +++ b/src/init.c @@ -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 */ } /* Return the user's home directory (strdup-ed), or NULL if none is diff --git a/src/main.c b/src/main.c index 1998fde9..0fb65f3b 100644 --- a/src/main.c +++ b/src/main.c @@ -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); } -- 2.39.2