about summary refs log tree commit diff
path: root/inet/getnameinfo.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2007-07-12 18:26:36 +0000
committerJakub Jelinek <jakub@redhat.com>2007-07-12 18:26:36 +0000
commit0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (patch)
tree2ea1f8305970753e4a657acb2ccc15ca3eec8e2c /inet/getnameinfo.c
parent7d58530341304d403a6626d7f7a1913165fe2f32 (diff)
downloadglibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.gz
glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.xz
glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.zip
2.5-18.1
Diffstat (limited to 'inet/getnameinfo.c')
-rw-r--r--inet/getnameinfo.c96
1 files changed, 38 insertions, 58 deletions
diff --git a/inet/getnameinfo.c b/inet/getnameinfo.c
index 493a423c10..b7b2b151b2 100644
--- a/inet/getnameinfo.c
+++ b/inet/getnameinfo.c
@@ -203,48 +203,40 @@ getnameinfo (const struct sockaddr *sa, socklen_t addrlen, char *host,
 	if (!(flags & NI_NUMERICHOST))
 	  {
 	    struct hostent *h = NULL;
+	    if (sa->sa_family == AF_INET6)
+	      {
+		while (__gethostbyaddr_r ((const void *) &(((const struct sockaddr_in6 *) sa)->sin6_addr),
+					  sizeof(struct in6_addr),
+					  AF_INET6, &th, tmpbuf, tmpbuflen,
+					  &h, &herrno))
+		  if (herrno == NETDB_INTERNAL && errno == ERANGE)
+		    tmpbuf = extend_alloca (tmpbuf, tmpbuflen, 2 * tmpbuflen);
+		  else
+		    break;
+	      }
+	    else
+	      {
+		while (__gethostbyaddr_r ((const void *) &(((const struct sockaddr_in *)sa)->sin_addr),
+					  sizeof(struct in_addr), AF_INET,
+					  &th, tmpbuf, tmpbuflen,
+					  &h, &herrno))
+		  if (herrno == NETDB_INTERNAL && errno == ERANGE)
+		    tmpbuf = extend_alloca (tmpbuf, tmpbuflen, 2 * tmpbuflen);
+		  else
+		    break;
+	      }
+
 	    if (h == NULL)
 	      {
-		if (sa->sa_family == AF_INET6)
+		if (herrno == NETDB_INTERNAL)
 		  {
-		    while (__gethostbyaddr_r ((const void *) &(((const struct sockaddr_in6 *) sa)->sin6_addr),
-					      sizeof(struct in6_addr),
-					      AF_INET6, &th, tmpbuf, tmpbuflen,
-					      &h, &herrno))
-		      {
-			if (herrno == NETDB_INTERNAL)
-			  {
-			    if (errno == ERANGE)
-			      tmpbuf = extend_alloca (tmpbuf, tmpbuflen,
-						      2 * tmpbuflen);
-			    else
-			      {
-				__set_h_errno (herrno);
-				__set_errno (serrno);
-				return EAI_SYSTEM;
-			      }
-			  }
-			else
-			  {
-			    break;
-			  }
-		      }
+		    __set_h_errno (herrno);
+		    return EAI_SYSTEM;
 		  }
-		else
+		if (herrno == TRY_AGAIN)
 		  {
-		    while (__gethostbyaddr_r ((const void *) &(((const struct sockaddr_in *)sa)->sin_addr),
-					      sizeof(struct in_addr), AF_INET,
-					      &th, tmpbuf, tmpbuflen,
-					      &h, &herrno))
-		      {
-			if (errno == ERANGE)
-			  tmpbuf = extend_alloca (tmpbuf, tmpbuflen,
-						  2 * tmpbuflen);
-			else
-			  {
-			    break;
-			  }
-		      }
+		    __set_h_errno (herrno);
+		    return EAI_AGAIN;
 		  }
 	      }
 
@@ -361,10 +353,7 @@ getnameinfo (const struct sockaddr *sa, socklen_t addrlen, char *host,
 				 (const void *) &(((const struct sockaddr_in *) sa)->sin_addr),
 				 host, hostlen);
 		if (c == NULL)
-		  {
-		    __set_errno (serrno);
-		    return EAI_SYSTEM;
-		  }
+		  return EAI_SYSTEM;
 	      }
 	    ok = 1;
 	  }
@@ -403,25 +392,16 @@ getnameinfo (const struct sockaddr *sa, socklen_t addrlen, char *host,
 	if (!(flags & NI_NUMERICSERV))
 	  {
 	    struct servent *s, ts;
-	    while (__getservbyport_r (((const struct sockaddr_in *) sa)->sin_port,
-				      ((flags & NI_DGRAM) ? "udp" : "tcp"),
-				      &ts, tmpbuf, tmpbuflen, &s))
+	    int e;
+	    while ((e = __getservbyport_r (((const struct sockaddr_in *) sa)->sin_port,
+					   ((flags & NI_DGRAM)
+					    ? "udp" : "tcp"),
+					   &ts, tmpbuf, tmpbuflen, &s)))
 	      {
-		if (herrno == NETDB_INTERNAL)
-		  {
-		    if (errno == ERANGE)
-		      tmpbuf = extend_alloca (tmpbuf, tmpbuflen,
-					      2 * tmpbuflen);
-		    else
-		      {
-			__set_errno (serrno);
-			return EAI_SYSTEM;
-		      }
-		  }
+		if (e == ERANGE)
+		  tmpbuf = extend_alloca (tmpbuf, tmpbuflen, 2 * tmpbuflen);
 		else
-		  {
-		    break;
-		  }
+		  break;
 	      }
 	    if (s)
 	      {