1 --- netkit-telnet-0.17/telnet/commands.c.old 2006-04-30 10:24:49.000000000 -0700
2 +++ netkit-telnet-0.17/telnet/commands.c 2006-04-30 10:37:10.000000000 -0700
5 /* If this is not the full name, try to get it via DNS */
6 if (strchr(hbuf, '.') == 0) {
7 - struct hostent *he = gethostbyname(hbuf);
9 - strncpy(hbuf, he->h_name, sizeof hbuf-1);
10 + struct addrinfo hints;
11 + struct addrinfo *res;
12 + memset (&hints, '\0', sizeof (hints));
13 + hints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG | AI_CANONNAME;
14 + if (getaddrinfo (hbuf, NULL, &hints, &res) == 0) {
15 + if (res->ai_canonname != NULL)
16 + strncpy(hbuf, res->ai_canonname, sizeof hbuf-1);
19 hbuf[sizeof hbuf-1] = '\0';
22 @@ -2832,17 +2838,15 @@
26 - if ((tmp = inet_addr(cp)) != -1) {
27 - sin_addr.s_addr = tmp;
28 - } else if ((host = gethostbyname(cp))) {
30 - memmove((caddr_t)&sin_addr,
31 - host->h_addr_list[0],
34 - memmove((caddr_t)&sin_addr, host->h_addr,
37 + struct addrinfo hints;
38 + memset (&hints, '\0', sizeof (hints));
39 + // XXX The code here seems to allow only IPv4 addresses.
40 + hints.ai_family = AF_INET;
41 + hints.ai_flags = AI_ADDRCONFIG;
42 + struct addrinfo *aires;
43 + if (getaddrinfo (cp, NULL, &hints, &aires) == 0) {
44 + sin_addr = ((struct sockaddr_in *) aires->ai_addr)->sin_addr;
45 + freeaddrinfo (aires);