+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
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,
};
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 *));
#include "host.h"
#include "url.h"
#include "hash.h"
+#include "connect.h" /* for socket_has_inet6 */
#ifndef errno
extern int errno;
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)
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
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_("\
}
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);
}