aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2002-08-29 08:51:26 +0000
committerUlrich Drepper <drepper@redhat.com>2002-08-29 08:51:26 +0000
commit160d067b046c2ee3296853129d1ea9a99156e2b8 (patch)
tree77134f8afec02ad11c0582ac323ef25c0bf04975
parent01beb5b9ff8fb38f6517837b42eea8f5ff7060d9 (diff)
downloadglibc-160d067b046c2ee3296853129d1ea9a99156e2b8.zip
glibc-160d067b046c2ee3296853129d1ea9a99156e2b8.tar.gz
glibc-160d067b046c2ee3296853129d1ea9a99156e2b8.tar.bz2
(gaih_inet): Fix code to determine canonical name.
-rw-r--r--sysdeps/posix/getaddrinfo.c54
-rw-r--r--time/strptime.c18
2 files changed, 55 insertions, 17 deletions
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 5e09a9f..2dc5e90 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -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.
*/
- char buffer[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
-
while (at2 != NULL)
{
if (req->ai_flags & AI_CANONNAME)
@@ -582,9 +580,6 @@ gaih_inet (const char *name, const struct gaih_service *service,
tmpbuflen *= 2;
tmpbuf = __alloca (tmpbuflen);
- if (tmpbuf == NULL)
- return -EAI_MEMORY;
-
rc = __gethostbyaddr_r (at2->addr,
((at2->family == AF_INET6)
? sizeof(struct in6_addr)
@@ -601,10 +596,42 @@ gaih_inet (const char *name, const struct gaih_service *service,
return -EAI_SYSTEM;
}
- if (h == NULL)
- c = inet_ntop (at2->family, at2->addr, buffer, sizeof(buffer));
- else
+ if (h != NULL)
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)
return GAIH_OKIFUNSPEC | -EAI_NONAME;
@@ -758,10 +785,12 @@ getaddrinfo (const char *name, const char *service,
last_i = i;
if (hints->ai_family == AF_UNSPEC && (i & GAIH_OKIFUNSPEC))
- continue;
+ {
+ ++g;
+ continue;
+ }
- if (p)
- freeaddrinfo (p);
+ freeaddrinfo (p);
return -(i & GAIH_EAI);
}
@@ -784,8 +813,7 @@ getaddrinfo (const char *name, const char *service,
if (pai == NULL && last_i == 0)
return 0;
- if (p)
- freeaddrinfo (p);
+ freeaddrinfo (p);
return last_i ? -(last_i & GAIH_EAI) : EAI_NONAME;
}
diff --git a/time/strptime.c b/time/strptime.c
index 5d8fe90..7208dde 100644
--- a/time/strptime.c
+++ b/time/strptime.c
@@ -71,11 +71,19 @@ localtime_r (t, tp)
#define match_char(ch1, ch2) if (ch1 != ch2) return NULL
#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); \
int result = strncasecmp ((cs1), (s2), len) == 0; \
if (result) (s2) += len; \
result; })
+# endif
#else
/* Oh come on. Get a reasonable compiler. */
# 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_DECL __locale_t locale;
# define HELPER_LOCALE_ARG , current
+# define ISSPACE(Ch) __isspace_l (Ch, locale)
#else
# define LOCALE_PARAM
# define LOCALE_ARG
@@ -213,6 +222,7 @@ const unsigned short int __mon_yday[2][13] =
# else
# define HELPER_LOCALE_ARG
# endif
+# define ISSPACE(Ch) isspace (Ch)
#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
space in the input string. */
- if (isspace (*fmt))
+ if (ISSPACE (*fmt))
{
- while (isspace (*rp))
+ while (ISSPACE (*rp))
++rp;
++fmt;
continue;
@@ -529,7 +539,7 @@ strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
case 'n':
case 't':
/* Match any white space. */
- while (isspace (*rp))
+ while (ISSPACE (*rp))
++rp;
break;
case 'p':