]> git.ipfire.org Git - ipfire-2.x.git/blob - src/patches/telnet-gethostbyname.patch
squid: Update to 4.4 (stable)
[ipfire-2.x.git] / src / patches / telnet-gethostbyname.patch
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
3 @@ -1669,9 +1669,15 @@
4
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);
8 - if (he != 0)
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);
17 + freeaddrinfo (res);
18 + }
19 hbuf[sizeof hbuf-1] = '\0';
20 }
21
22 @@ -2832,17 +2838,15 @@
23 if (!c)
24 cp2 = 0;
25
26 - if ((tmp = inet_addr(cp)) != -1) {
27 - sin_addr.s_addr = tmp;
28 - } else if ((host = gethostbyname(cp))) {
29 -#if defined(h_addr)
30 - memmove((caddr_t)&sin_addr,
31 - host->h_addr_list[0],
32 - sizeof(sin_addr));
33 -#else
34 - memmove((caddr_t)&sin_addr, host->h_addr,
35 - sizeof(sin_addr));
36 -#endif
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);
46 } else {
47 *cpp = cp;
48 return(0);