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