mirror of
https://sourceware.org/git/glibc.git
synced 2025-01-08 18:30:18 +00:00
(gaih_inet): Fix code to determine canonical name.
This commit is contained in:
parent
01beb5b9ff
commit
160d067b04
@ -564,8 +564,6 @@ gaih_inet (const char *name, const struct gaih_service *service,
|
|||||||
/*
|
/*
|
||||||
buffer is the size of an unformatted IPv6 address in printable format.
|
buffer is the size of an unformatted IPv6 address in printable format.
|
||||||
*/
|
*/
|
||||||
char buffer[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
|
|
||||||
|
|
||||||
while (at2 != NULL)
|
while (at2 != NULL)
|
||||||
{
|
{
|
||||||
if (req->ai_flags & AI_CANONNAME)
|
if (req->ai_flags & AI_CANONNAME)
|
||||||
@ -582,9 +580,6 @@ gaih_inet (const char *name, const struct gaih_service *service,
|
|||||||
tmpbuflen *= 2;
|
tmpbuflen *= 2;
|
||||||
tmpbuf = __alloca (tmpbuflen);
|
tmpbuf = __alloca (tmpbuflen);
|
||||||
|
|
||||||
if (tmpbuf == NULL)
|
|
||||||
return -EAI_MEMORY;
|
|
||||||
|
|
||||||
rc = __gethostbyaddr_r (at2->addr,
|
rc = __gethostbyaddr_r (at2->addr,
|
||||||
((at2->family == AF_INET6)
|
((at2->family == AF_INET6)
|
||||||
? sizeof(struct in6_addr)
|
? sizeof(struct in6_addr)
|
||||||
@ -601,10 +596,42 @@ gaih_inet (const char *name, const struct gaih_service *service,
|
|||||||
return -EAI_SYSTEM;
|
return -EAI_SYSTEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (h == NULL)
|
if (h != NULL)
|
||||||
c = inet_ntop (at2->family, at2->addr, buffer, sizeof(buffer));
|
|
||||||
else
|
|
||||||
c = h->h_name;
|
c = h->h_name;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* We have to try to get the canonical in some other
|
||||||
|
way. If we are looking for either AF_INET or
|
||||||
|
AF_INET6 try the other line. */
|
||||||
|
if (req->ai_family == AF_UNSPEC)
|
||||||
|
{
|
||||||
|
struct addrinfo *p = NULL;
|
||||||
|
struct addrinfo **end = &p;
|
||||||
|
struct addrinfo localreq = *req;
|
||||||
|
struct addrinfo *runp;
|
||||||
|
|
||||||
|
localreq.ai_family = AF_INET + AF_INET6 - at2->family;
|
||||||
|
(void) gaih_inet (name, service, &localreq, end);
|
||||||
|
|
||||||
|
runp = p;
|
||||||
|
while (runp != NULL)
|
||||||
|
{
|
||||||
|
if (p->ai_canonname != name)
|
||||||
|
{
|
||||||
|
c = strdupa (p->ai_canonname);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
runp = runp->ai_next;
|
||||||
|
}
|
||||||
|
|
||||||
|
freeaddrinfo (p);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If this code is used the missing canonical name is
|
||||||
|
substituted with the name passed in by the user. */
|
||||||
|
if (c == NULL)
|
||||||
|
c = name;
|
||||||
|
}
|
||||||
|
|
||||||
if (c == NULL)
|
if (c == NULL)
|
||||||
return GAIH_OKIFUNSPEC | -EAI_NONAME;
|
return GAIH_OKIFUNSPEC | -EAI_NONAME;
|
||||||
@ -758,10 +785,12 @@ getaddrinfo (const char *name, const char *service,
|
|||||||
last_i = i;
|
last_i = i;
|
||||||
|
|
||||||
if (hints->ai_family == AF_UNSPEC && (i & GAIH_OKIFUNSPEC))
|
if (hints->ai_family == AF_UNSPEC && (i & GAIH_OKIFUNSPEC))
|
||||||
continue;
|
{
|
||||||
|
++g;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (p)
|
freeaddrinfo (p);
|
||||||
freeaddrinfo (p);
|
|
||||||
|
|
||||||
return -(i & GAIH_EAI);
|
return -(i & GAIH_EAI);
|
||||||
}
|
}
|
||||||
@ -784,8 +813,7 @@ getaddrinfo (const char *name, const char *service,
|
|||||||
if (pai == NULL && last_i == 0)
|
if (pai == NULL && last_i == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (p)
|
freeaddrinfo (p);
|
||||||
freeaddrinfo (p);
|
|
||||||
|
|
||||||
return last_i ? -(last_i & GAIH_EAI) : EAI_NONAME;
|
return last_i ? -(last_i & GAIH_EAI) : EAI_NONAME;
|
||||||
}
|
}
|
||||||
|
@ -71,11 +71,19 @@ localtime_r (t, tp)
|
|||||||
|
|
||||||
#define match_char(ch1, ch2) if (ch1 != ch2) return NULL
|
#define match_char(ch1, ch2) if (ch1 != ch2) return NULL
|
||||||
#if defined __GNUC__ && __GNUC__ >= 2
|
#if defined __GNUC__ && __GNUC__ >= 2
|
||||||
# define match_string(cs1, s2) \
|
# ifdef USE_IN_EXTENDED_LOCALE_MODEL
|
||||||
|
# define match_string(cs1, s2) \
|
||||||
|
({ size_t len = strlen (cs1); \
|
||||||
|
int result = __strncasecmp_l ((cs1), (s2), len, locale) == 0; \
|
||||||
|
if (result) (s2) += len; \
|
||||||
|
result; })
|
||||||
|
# else
|
||||||
|
# define match_string(cs1, s2) \
|
||||||
({ size_t len = strlen (cs1); \
|
({ size_t len = strlen (cs1); \
|
||||||
int result = strncasecmp ((cs1), (s2), len) == 0; \
|
int result = strncasecmp ((cs1), (s2), len) == 0; \
|
||||||
if (result) (s2) += len; \
|
if (result) (s2) += len; \
|
||||||
result; })
|
result; })
|
||||||
|
# endif
|
||||||
#else
|
#else
|
||||||
/* Oh come on. Get a reasonable compiler. */
|
/* Oh come on. Get a reasonable compiler. */
|
||||||
# define match_string(cs1, s2) \
|
# define match_string(cs1, s2) \
|
||||||
@ -203,6 +211,7 @@ const unsigned short int __mon_yday[2][13] =
|
|||||||
# define LOCALE_PARAM_PROTO , __locale_t locale
|
# define LOCALE_PARAM_PROTO , __locale_t locale
|
||||||
# define LOCALE_PARAM_DECL __locale_t locale;
|
# define LOCALE_PARAM_DECL __locale_t locale;
|
||||||
# define HELPER_LOCALE_ARG , current
|
# define HELPER_LOCALE_ARG , current
|
||||||
|
# define ISSPACE(Ch) __isspace_l (Ch, locale)
|
||||||
#else
|
#else
|
||||||
# define LOCALE_PARAM
|
# define LOCALE_PARAM
|
||||||
# define LOCALE_ARG
|
# define LOCALE_ARG
|
||||||
@ -213,6 +222,7 @@ const unsigned short int __mon_yday[2][13] =
|
|||||||
# else
|
# else
|
||||||
# define HELPER_LOCALE_ARG
|
# define HELPER_LOCALE_ARG
|
||||||
# endif
|
# endif
|
||||||
|
# define ISSPACE(Ch) isspace (Ch)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -306,9 +316,9 @@ strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
|
|||||||
{
|
{
|
||||||
/* A white space in the format string matches 0 more or white
|
/* A white space in the format string matches 0 more or white
|
||||||
space in the input string. */
|
space in the input string. */
|
||||||
if (isspace (*fmt))
|
if (ISSPACE (*fmt))
|
||||||
{
|
{
|
||||||
while (isspace (*rp))
|
while (ISSPACE (*rp))
|
||||||
++rp;
|
++rp;
|
||||||
++fmt;
|
++fmt;
|
||||||
continue;
|
continue;
|
||||||
@ -529,7 +539,7 @@ strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
|
|||||||
case 'n':
|
case 'n':
|
||||||
case 't':
|
case 't':
|
||||||
/* Match any white space. */
|
/* Match any white space. */
|
||||||
while (isspace (*rp))
|
while (ISSPACE (*rp))
|
||||||
++rp;
|
++rp;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
|
Loading…
Reference in New Issue
Block a user