Blame SOURCES/telnet-gethostbyname.patch

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