public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Filter results from gethostbyname4_r according to request flags
@ 2011-06-16 14:21 Andreas Schwab
  2011-06-21 15:23 ` Andreas Schwab
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2011-06-16 14:21 UTC (permalink / raw)
  To: libc-hacker

2011-06-16  Andreas Schwab  <schwab@redhat.com>

	[BZ #12885]
	* sysdeps/posix/getaddrinfo.c (gaih_inet): Filter results from
	gethostbyname4_r according to request flags.
---
 sysdeps/posix/getaddrinfo.c |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 469abe2..1db1e26 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -889,7 +889,29 @@ gaih_inet (const char *name, const struct gaih_service *service,
 			canon = (*pat)->name;
 
 		      while (*pat != NULL)
-			pat = &((*pat)->next);
+			{
+			  if ((*pat)->family == AF_INET
+			      && req->ai_family == AF_INET6
+			      && (req->ai_flags & AI_V4MAPPED) != 0)
+			    {
+			      uint32_t *pataddr = (*pat)->addr;
+			      (*pat)->family = AF_INET6;
+			      pataddr[3] = pataddr[0];
+			      pataddr[2] = htonl (0xffff);
+			      pataddr[1] = 0;
+			      pataddr[0] = 0;
+			      pat = &(*pat)->next;
+			    }
+			  else if ((req->ai_family == AF_UNSPEC
+				    || (*pat)->family == req->ai_family))
+			    {
+			      if ((*pat)->family == AF_INET6)
+				got_ipv6 = true;
+			      pat = &(*pat)->next;
+			    }
+			  else
+			    *pat = (*pat)->next;
+			}
 		    }
 		}
 	      else
-- 
1.7.5.4

-- 
Andreas Schwab, schwab@redhat.com
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84  5EC7 45C6 250E 6F00 984E
"And now for something completely different."

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] Filter results from gethostbyname4_r according to request flags
  2011-06-16 14:21 [PATCH] Filter results from gethostbyname4_r according to request flags Andreas Schwab
@ 2011-06-21 15:23 ` Andreas Schwab
  2011-06-21 21:06   ` Ulrich Drepper
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2011-06-21 15:23 UTC (permalink / raw)
  To: libc-hacker

2011-06-21  Andreas Schwab  <schwab@redhat.com>

	[BZ #12885]
	* sysdeps/posix/getaddrinfo.c (gaih_inet): Filter results from
	gethostbyname4_r according to request flags.
---
 sysdeps/posix/getaddrinfo.c |   38 +++++++++++++++++++++++++++++++++++---
 1 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 469abe2..7acc73d 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -881,16 +881,48 @@ gaih_inet (const char *name, const struct gaih_service *service,
 			}
 		    }
 
-		  no_inet6_data = no_data;
-
 		  if (status == NSS_STATUS_SUCCESS)
 		    {
 		      if ((req->ai_flags & AI_CANONNAME) != 0 && canon == NULL)
 			canon = (*pat)->name;
 
 		      while (*pat != NULL)
-			pat = &((*pat)->next);
+			{
+			  if ((*pat)->family == AF_INET
+			      && req->ai_family == AF_INET6
+			      && (req->ai_flags & AI_V4MAPPED) != 0)
+			    {
+			      uint32_t *pataddr = (*pat)->addr;
+			      (*pat)->family = AF_INET6;
+			      pataddr[3] = pataddr[0];
+			      pataddr[2] = htonl (0xffff);
+			      pataddr[1] = 0;
+			      pataddr[0] = 0;
+			      pat = &(*pat)->next;
+			    }
+			  else if ((req->ai_family == AF_UNSPEC
+				    || (*pat)->family == req->ai_family))
+			    {
+			      if ((*pat)->family == AF_INET6)
+				got_ipv6 = true;
+			      pat = &(*pat)->next;
+			    }
+			  else if (*pat == at)
+			    {
+			      if ((*pat)->next != NULL)
+				memcpy (*pat, (*pat)->next, sizeof (**pat));
+			      else
+				{
+				  no_data = 1;
+				  break;
+				}
+			    }
+			  else
+			    *pat = (*pat)->next;
+			}
 		    }
+
+		  no_inet6_data = no_data;
 		}
 	      else
 		{
-- 
1.7.5.4


-- 
Andreas Schwab, schwab@redhat.com
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84  5EC7 45C6 250E 6F00 984E
"And now for something completely different."

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Filter results from gethostbyname4_r according to request flags
  2011-06-21 15:23 ` Andreas Schwab
@ 2011-06-21 21:06   ` Ulrich Drepper
  2011-06-22 12:58     ` Andreas Schwab
  0 siblings, 1 reply; 4+ messages in thread
From: Ulrich Drepper @ 2011-06-21 21:06 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-hacker

On Tue, Jun 21, 2011 at 11:23, Andreas Schwab <schwab@redhat.com> wrote:
> 2011-06-21  Andreas Schwab  <schwab@redhat.com>
>
>        [BZ #12885]
>        * sysdeps/posix/getaddrinfo.c (gaih_inet): Filter results from
>        gethostbyname4_r according to request flags.

This patch isn't correct.  We need to ignore the IPv4 entries, keep
track of whether we found any data.  And there is no reason to copy
anything.  I think the patch I applied is correct.  Give it a try.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Filter results from gethostbyname4_r according to request flags
  2011-06-21 21:06   ` Ulrich Drepper
@ 2011-06-22 12:58     ` Andreas Schwab
  0 siblings, 0 replies; 4+ messages in thread
From: Andreas Schwab @ 2011-06-22 12:58 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: libc-hacker

At last my patch was tested.

2011-06-22  Andreas Schwab  <schwab@redhat.com>

	* sysdeps/posix/getaddrinfo.c (gaih_inet): Fix last change.
---
 sysdeps/posix/getaddrinfo.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 396f120..e6df220 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -894,7 +894,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
 			      pat = &((*pat)->next);
 			      no_data = 0;
 			    }
-			  else if ((*pat)->family == AF_UNSPEC
+			  else if (req->ai_family == AF_UNSPEC
 				   || (*pat)->family == req->ai_family)
 			    {
 			      pat = &((*pat)->next);
-- 
1.7.5.4

-- 
Andreas Schwab, schwab@redhat.com
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84  5EC7 45C6 250E 6F00 984E
"And now for something completely different."

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-06-22 12:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-16 14:21 [PATCH] Filter results from gethostbyname4_r according to request flags Andreas Schwab
2011-06-21 15:23 ` Andreas Schwab
2011-06-21 21:06   ` Ulrich Drepper
2011-06-22 12:58     ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).