Blame SOURCES/telnet-gethostbyname.patch

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