mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
[svn] Special-case numeric addresses only in the IPv4 case.
This commit is contained in:
parent
8ccc51e5af
commit
5921fb2d57
@ -1,3 +1,8 @@
|
|||||||
|
2003-11-10 Hrvoje Niksic <hniksic@xemacs.org>
|
||||||
|
|
||||||
|
* host.c (lookup_host): Special-case the numeric addresses only in
|
||||||
|
the non-IPv6 case.
|
||||||
|
|
||||||
2003-11-10 Hrvoje Niksic <hniksic@xemacs.org>
|
2003-11-10 Hrvoje Niksic <hniksic@xemacs.org>
|
||||||
|
|
||||||
* connect.c (resolve_bind_address): Call lookup_host_passive.
|
* connect.c (resolve_bind_address): Call lookup_host_passive.
|
||||||
|
58
src/host.c
58
src/host.c
@ -83,10 +83,10 @@ extern int h_errno;
|
|||||||
static struct hash_table *host_name_addresses_map;
|
static struct hash_table *host_name_addresses_map;
|
||||||
|
|
||||||
#ifdef ENABLE_IPV6
|
#ifdef ENABLE_IPV6
|
||||||
/* The default IP family for looking up host names. This should be
|
/* The IP family to request when connecting to remote hosts. This
|
||||||
moved to an entry in struct options when we implement the
|
should be moved to an entry in struct options when we implement the
|
||||||
--inet4/--inet6 flags. */
|
--inet4/--inet6 flags. */
|
||||||
static int ip_default_family = AF_UNSPEC;
|
static int requested_family = AF_UNSPEC;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Lists of addresses. This should eventually be extended to handle
|
/* Lists of addresses. This should eventually be extended to handle
|
||||||
@ -484,42 +484,18 @@ lookup_host (const char *host, int silent)
|
|||||||
{
|
{
|
||||||
struct address_list *al = NULL;
|
struct address_list *al = NULL;
|
||||||
|
|
||||||
#ifdef ENABLE_IPV6
|
/* If we're not using getaddrinfo, first check if HOST names a
|
||||||
int err;
|
numeric IPv4 address. This was necessary under old (e.g. Ultrix)
|
||||||
struct addrinfo hints, *res;
|
implementations of gethostbyname that couldn't handle numeric
|
||||||
xzero (hints);
|
addresses (!). This is not done under IPv6 because getaddrinfo
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
always handles numeric addresses. */
|
||||||
hints.ai_family = ip_default_family;
|
#ifndef ENABLE_IPV6
|
||||||
#endif
|
|
||||||
|
|
||||||
/* First, try to check whether the address is already a numeric
|
|
||||||
address, in which case we don't want to cache it or bother with
|
|
||||||
setting up timeouts. Plus, old (e.g. Ultrix) implementations of
|
|
||||||
gethostbyname can't handle numeric addresses (!).
|
|
||||||
|
|
||||||
Where getaddrinfo is available, we do it using the AI_NUMERICHOST
|
|
||||||
flag. Without IPv6, we use inet_addr. */
|
|
||||||
|
|
||||||
#ifdef ENABLE_IPV6
|
|
||||||
hints.ai_flags = AI_NUMERICHOST;
|
|
||||||
|
|
||||||
/* No need to specify timeout, as we're not resolving HOST, but
|
|
||||||
merely translating it from the presentation (ASCII) to network
|
|
||||||
format. */
|
|
||||||
err = getaddrinfo (host, NULL, &hints, &res);
|
|
||||||
if (err == 0 && res != NULL)
|
|
||||||
{
|
|
||||||
al = address_list_from_addrinfo (res);
|
|
||||||
freeaddrinfo (res);
|
|
||||||
return al;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
{
|
{
|
||||||
uint32_t addr_ipv4 = (uint32_t)inet_addr (host);
|
uint32_t addr_ipv4 = (uint32_t)inet_addr (host);
|
||||||
if (addr_ipv4 != (uint32_t) -1)
|
if (addr_ipv4 != (uint32_t) -1)
|
||||||
{
|
{
|
||||||
/* The return value of inet_addr is in network byte order, so
|
/* No need to cache host->addr relation, just return the
|
||||||
we can just copy it to IP. */
|
address. */
|
||||||
char *vec[2];
|
char *vec[2];
|
||||||
vec[0] = (char *)&addr_ipv4;
|
vec[0] = (char *)&addr_ipv4;
|
||||||
vec[1] = NULL;
|
vec[1] = NULL;
|
||||||
@ -528,7 +504,7 @@ lookup_host (const char *host, int silent)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Then, try to find the host in the cache. */
|
/* Try to find the host in the cache. */
|
||||||
|
|
||||||
if (host_name_addresses_map)
|
if (host_name_addresses_map)
|
||||||
{
|
{
|
||||||
@ -548,6 +524,13 @@ lookup_host (const char *host, int silent)
|
|||||||
logprintf (LOG_VERBOSE, _("Resolving %s... "), host);
|
logprintf (LOG_VERBOSE, _("Resolving %s... "), host);
|
||||||
|
|
||||||
#ifdef ENABLE_IPV6
|
#ifdef ENABLE_IPV6
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
struct addrinfo hints, *res;
|
||||||
|
|
||||||
|
xzero (hints);
|
||||||
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
hints.ai_family = requested_family;
|
||||||
hints.ai_flags = 0;
|
hints.ai_flags = 0;
|
||||||
|
|
||||||
err = getaddrinfo_with_timeout (host, NULL, &hints, &res, opt.dns_timeout);
|
err = getaddrinfo_with_timeout (host, NULL, &hints, &res, opt.dns_timeout);
|
||||||
@ -560,6 +543,7 @@ lookup_host (const char *host, int silent)
|
|||||||
}
|
}
|
||||||
al = address_list_from_addrinfo (res);
|
al = address_list_from_addrinfo (res);
|
||||||
freeaddrinfo (res);
|
freeaddrinfo (res);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
struct hostent *hptr = gethostbyname_with_timeout (host, opt.dns_timeout);
|
struct hostent *hptr = gethostbyname_with_timeout (host, opt.dns_timeout);
|
||||||
@ -628,7 +612,7 @@ lookup_host_passive (const char *host)
|
|||||||
|
|
||||||
xzero (hints);
|
xzero (hints);
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
hints.ai_family = ip_default_family;
|
hints.ai_family = requested_family;
|
||||||
hints.ai_flags = AI_PASSIVE;
|
hints.ai_flags = AI_PASSIVE;
|
||||||
|
|
||||||
err = getaddrinfo (host, NULL, &hints, &res);
|
err = getaddrinfo (host, NULL, &hints, &res);
|
||||||
|
Loading…
Reference in New Issue
Block a user