Blame SOURCES/telnet-gethostbyname.patch

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