Blame SOURCES/telnet-gethostbyname.patch

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