[svn] Don't auto-set opt.ipv4_only on systems without IPv6 sockets.

This commit is contained in:
hniksic 2003-11-17 04:59:54 -08:00
parent a9d4f29c9e
commit 133d69ff24
6 changed files with 37 additions and 35 deletions

View 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

View 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,

View 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 *));

View 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)

View 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 */
}
/* Return the user's home directory (strdup-ed), or NULL if none is

View 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);
}