Blame SOURCES/telnet-gethostbyname.patch

b76cf7
--- netkit-telnet-0.17/telnet/commands.c.old	2006-04-30 10:24:49.000000000 -0700
b76cf7
+++ netkit-telnet-0.17/telnet/commands.c	2006-04-30 10:37:10.000000000 -0700
b76cf7
@@ -1669,9 +1669,15 @@
b76cf7
 
b76cf7
 		/* If this is not the full name, try to get it via DNS */
b76cf7
 		if (strchr(hbuf, '.') == 0) {
b76cf7
-			struct hostent *he = gethostbyname(hbuf);
b76cf7
-			if (he != 0)
b76cf7
-				strncpy(hbuf, he->h_name, sizeof hbuf-1);
b76cf7
+			struct addrinfo hints;
b76cf7
+			struct addrinfo *res;
b76cf7
+			memset (&hints, '\0', sizeof (hints));
b76cf7
+			hints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG | AI_CANONNAME;
b76cf7
+			if (getaddrinfo (hbuf, NULL, &hints, &res) == 0) {
b76cf7
+				if (res->ai_canonname != NULL)
b76cf7
+					strncpy(hbuf, res->ai_canonname, sizeof hbuf-1);
b76cf7
+				freeaddrinfo (res);
b76cf7
+			}
b76cf7
 			hbuf[sizeof hbuf-1] = '\0';
b76cf7
 		}
b76cf7
 
b76cf7
@@ -2832,17 +2838,15 @@
b76cf7
 		if (!c)
b76cf7
 			cp2 = 0;
b76cf7
 
b76cf7
-		if ((tmp = inet_addr(cp)) != -1) {
b76cf7
-			sin_addr.s_addr = tmp;
b76cf7
-		} else if ((host = gethostbyname(cp))) {
b76cf7
-#if	defined(h_addr)
b76cf7
-			memmove((caddr_t)&sin_addr,
b76cf7
-				host->h_addr_list[0], 
b76cf7
-				sizeof(sin_addr));
b76cf7
-#else
b76cf7
-			memmove((caddr_t)&sin_addr, host->h_addr, 
b76cf7
-				sizeof(sin_addr));
b76cf7
-#endif
b76cf7
+		struct addrinfo hints;
b76cf7
+		memset (&hints, '\0', sizeof (hints));
b76cf7
+		// XXX The code here seems to allow only IPv4 addresses.
b76cf7
+		hints.ai_family = AF_INET;
b76cf7
+		hints.ai_flags = AI_ADDRCONFIG;
b76cf7
+		struct addrinfo *aires;
b76cf7
+		if (getaddrinfo (cp, NULL, &hints, &aires) == 0) {
b76cf7
+			sin_addr = ((struct sockaddr_in *) aires->ai_addr)->sin_addr;
b76cf7
+			freeaddrinfo (aires);
b76cf7
 		} else {
b76cf7
 			*cpp = cp;
b76cf7
 			return(0);