about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--sysdeps/posix/getaddrinfo.c13
2 files changed, 18 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 5a5a2b5a7d..3b61bc8ce7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2013-10-25  Aurelien Jarno  <aurelien@aurel32.net>
+
+	[BZ #9954]
+	* sysdeps/posix/getaddrinfo.c (rfc3484_sort): do not assign native
+	result if the result has no associated interface.
+	* sysdeps/posix/getaddrinfo.c (getaddrinfo): correctly detect
+	interface for all 127.X.Y.Z addresses.
+
 2013-09-23  Carlos O'Donell  <carlos@redhat.com>
 
 	[BZ #15754]
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 7bb3ded9af..8a27f0ddb7 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -1735,13 +1735,13 @@ rfc3484_sort (const void *p1, const void *p2, void *arg)
 
 	      /* Fill in the results in all the records.  */
 	      for (int i = 0; i < src->nresults; ++i)
-		if (src->results[i].index == a1_index)
+		if (a1_index != -1 && src->results[i].index == a1_index)
 		  {
 		    assert (src->results[i].native == -1
 			    || src->results[i].native == a1_native);
 		    src->results[i].native = a1_native;
 		  }
-		else if (src->results[i].index == a2_index)
+		else if (a2_index != -1 && src->results[i].index == a2_index)
 		  {
 		    assert (src->results[i].native == -1
 			    || src->results[i].native == a2_native);
@@ -2601,7 +2601,14 @@ getaddrinfo (const char *name, const char *service,
 			  tmp.addr[0] = 0;
 			  tmp.addr[1] = 0;
 			  tmp.addr[2] = htonl (0xffff);
-			  tmp.addr[3] = sinp->sin_addr.s_addr;
+			  /* Special case for lo interface, the source address
+			     being possibly different than the interface
+			     address. */
+			  if ((ntohl(sinp->sin_addr.s_addr) & 0xff000000)
+			      == 0x7f000000)
+			    tmp.addr[3] = htonl(0x7f000001);
+			  else
+			    tmp.addr[3] = sinp->sin_addr.s_addr;
 			}
 		      else
 			{