telnet/telnet-bsd-1.2-no_gethostbyname.patch

54 lines
1.6 KiB
Diff
Raw Normal View History

Index: telnet/commands.c
===================================================================
--- telnet/commands.c.orig 2005-06-02 10:12:51.000000000 +0200
+++ telnet/commands.c 2009-05-22 01:27:21.108685000 +0200
@@ -1850,9 +1850,16 @@ env_init (void)
/* If this is not the full name, try to get it via DNS */
if (strchr (hbuf, '.') == 0)
{
- struct hostent *he = gethostbyname (hbuf);
- if (he != 0)
- strncpy (hbuf, he->h_name, sizeof hbuf - 1);
+ struct addrinfo hints;
+ struct addrinfo *res;
+ memset (&hints, '\0', sizeof (hints));
+ hints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG | AI_CANONNAME;
+ if (getaddrinfo (hbuf, NULL, &hints, &res) == 0) {
+ if (res->ai_canonname != NULL)
+ strncpy(hbuf, res->ai_canonname, sizeof hbuf-1);
+ freeaddrinfo (res);
+ }
+
hbuf[sizeof hbuf - 1] = '\0';
}
@@ -2919,19 +2926,16 @@ sourceroute (char *arg, char **cpp, int
}
if (!c)
cp2 = 0;
+ struct addrinfo hints;
+ memset (&hints, '\0', sizeof (hints));
+ // XXX The code here seems to allow only IPv4 addresses.
+ hints.ai_family = AF_INET;
+ hints.ai_flags = AI_ADDRCONFIG;
+ struct addrinfo *aires;
+ if (getaddrinfo (cp, NULL, &hints, &aires) == 0) {
+ sin_addr = ((struct sockaddr_in *) aires->ai_addr)->sin_addr;
+ freeaddrinfo (aires);
- if ((tmp = inet_addr (cp)) != -1)
- {
- sin_addr.s_addr = tmp;
- }
- else if ((host = gethostbyname (cp)))
- {
-#if defined(h_addr)
- memmove ((caddr_t) & sin_addr,
- host->h_addr_list[0], sizeof (sin_addr));
-#else
- memmove ((caddr_t) & sin_addr, host->h_addr, sizeof (sin_addr));
-#endif
}
else
{