mirror of
https://github.com/moparisthebest/curl
synced 2024-08-13 17:03:50 -04:00
Support lookup of IPv4 literals in ares_gethostbyname(), even when the address family is set to AF_INET6.
This commit is contained in:
parent
b0b2824b58
commit
8d1e46bdcc
@ -245,15 +245,16 @@ static int fake_hostent(const char *name, int family, ares_host_callback callbac
|
|||||||
struct in_addr in;
|
struct in_addr in;
|
||||||
struct in6_addr in6;
|
struct in6_addr in6;
|
||||||
|
|
||||||
if (family == AF_INET)
|
if (family == AF_INET || family == AF_INET6)
|
||||||
{
|
{
|
||||||
/* It only looks like an IP address if it's all numbers and dots. */
|
/* It only looks like an IP address if it's all numbers and dots. */
|
||||||
int numdots = 0;
|
int numdots = 0, valid = 1;
|
||||||
const char *p;
|
const char *p;
|
||||||
for (p = name; *p; p++)
|
for (p = name; *p; p++)
|
||||||
{
|
{
|
||||||
if (!ISDIGIT(*p) && *p != '.') {
|
if (!ISDIGIT(*p) && *p != '.') {
|
||||||
return 0;
|
valid = 0;
|
||||||
|
break;
|
||||||
} else if (*p == '.') {
|
} else if (*p == '.') {
|
||||||
numdots++;
|
numdots++;
|
||||||
}
|
}
|
||||||
@ -262,12 +263,15 @@ static int fake_hostent(const char *name, int family, ares_host_callback callbac
|
|||||||
/* if we don't have 3 dots, it is illegal
|
/* if we don't have 3 dots, it is illegal
|
||||||
* (although inet_addr doesn't think so).
|
* (although inet_addr doesn't think so).
|
||||||
*/
|
*/
|
||||||
if (numdots != 3)
|
if (numdots != 3 || !valid)
|
||||||
result = 0;
|
result = 0;
|
||||||
else
|
else
|
||||||
result = ((in.s_addr = inet_addr(name)) == INADDR_NONE ? 0 : 1);
|
result = ((in.s_addr = inet_addr(name)) == INADDR_NONE ? 0 : 1);
|
||||||
|
|
||||||
|
if (result)
|
||||||
|
family = AF_INET;
|
||||||
}
|
}
|
||||||
else if (family == AF_INET6)
|
if (family == AF_INET6)
|
||||||
result = (ares_inet_pton(AF_INET6, name, &in6) < 1 ? 0 : 1);
|
result = (ares_inet_pton(AF_INET6, name, &in6) < 1 ? 0 : 1);
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
|
Loading…
Reference in New Issue
Block a user