nameserv: require getaddrinfo() and getnameinfo()
Remove support for the long-deprecated gethostbyname() and gethostbyaddr() functions.
This commit is contained in:
parent
2d39a12f51
commit
10c760a80c
2 changed files with 3 additions and 61 deletions
5
configure
vendored
5
configure
vendored
|
@ -684,10 +684,11 @@ if [ $try_clock_gettime = "1" ]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test_code 'getaddrinfo()' 'sys/types.h sys/socket.h netdb.h' '' "$LIBS" \
|
if ! test_code 'getaddrinfo()' 'sys/types.h sys/socket.h netdb.h' '' "$LIBS" \
|
||||||
'return getaddrinfo(0, 0, 0, 0);'
|
'return getaddrinfo(0, 0, 0, 0);'
|
||||||
then
|
then
|
||||||
add_def HAVE_GETADDRINFO
|
echo "error: getaddrinfo() not found"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $feat_asyncdns = "1" ] && \
|
if [ $feat_asyncdns = "1" ] && \
|
||||||
|
|
59
nameserv.c
59
nameserv.c
|
@ -50,7 +50,6 @@ DNS_SetAddressFamily(int family)
|
||||||
DNS_Status
|
DNS_Status
|
||||||
DNS_Name2IPAddress(const char *name, IPAddr *ip_addrs, int max_addrs)
|
DNS_Name2IPAddress(const char *name, IPAddr *ip_addrs, int max_addrs)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_GETADDRINFO
|
|
||||||
struct addrinfo hints, *res, *ai;
|
struct addrinfo hints, *res, *ai;
|
||||||
int i, result;
|
int i, result;
|
||||||
|
|
||||||
|
@ -113,42 +112,6 @@ DNS_Name2IPAddress(const char *name, IPAddr *ip_addrs, int max_addrs)
|
||||||
freeaddrinfo(res);
|
freeaddrinfo(res);
|
||||||
|
|
||||||
return !max_addrs || ip_addrs[0].family != IPADDR_UNSPEC ? DNS_Success : DNS_Failure;
|
return !max_addrs || ip_addrs[0].family != IPADDR_UNSPEC ? DNS_Success : DNS_Failure;
|
||||||
#else
|
|
||||||
struct hostent *host;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (address_family != IPADDR_UNSPEC && address_family != IPADDR_INET4)
|
|
||||||
return DNS_Failure;
|
|
||||||
|
|
||||||
max_addrs = MIN(max_addrs, DNS_MAX_ADDRESSES);
|
|
||||||
|
|
||||||
host = gethostbyname(name);
|
|
||||||
|
|
||||||
if (host == NULL) {
|
|
||||||
if (h_errno == TRY_AGAIN)
|
|
||||||
return DNS_TryAgain;
|
|
||||||
} else {
|
|
||||||
if (host->h_addrtype != AF_INET || !host->h_addr_list[0])
|
|
||||||
return DNS_Failure;
|
|
||||||
|
|
||||||
for (i = 0; host->h_addr_list[i] && i < max_addrs; i++) {
|
|
||||||
ip_addrs[i].family = IPADDR_INET4;
|
|
||||||
ip_addrs[i].addr.in4 = ntohl(*(uint32_t *)host->h_addr_list[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (; i < max_addrs; i++)
|
|
||||||
ip_addrs[i].family = IPADDR_UNSPEC;
|
|
||||||
|
|
||||||
return DNS_Success;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef FORCE_DNSRETRY
|
|
||||||
return DNS_TryAgain;
|
|
||||||
#else
|
|
||||||
return DNS_Failure;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
@ -157,8 +120,6 @@ int
|
||||||
DNS_IPAddress2Name(IPAddr *ip_addr, char *name, int len)
|
DNS_IPAddress2Name(IPAddr *ip_addr, char *name, int len)
|
||||||
{
|
{
|
||||||
char *result = NULL;
|
char *result = NULL;
|
||||||
|
|
||||||
#ifdef FEAT_IPV6
|
|
||||||
struct sockaddr_in6 in6;
|
struct sockaddr_in6 in6;
|
||||||
IPSockAddr ip_saddr;
|
IPSockAddr ip_saddr;
|
||||||
socklen_t slen;
|
socklen_t slen;
|
||||||
|
@ -170,26 +131,6 @@ DNS_IPAddress2Name(IPAddr *ip_addr, char *name, int len)
|
||||||
slen = SCK_IPSockAddrToSockaddr(&ip_saddr, (struct sockaddr *)&in6, sizeof (in6));
|
slen = SCK_IPSockAddrToSockaddr(&ip_saddr, (struct sockaddr *)&in6, sizeof (in6));
|
||||||
if (!getnameinfo((struct sockaddr *)&in6, slen, hbuf, sizeof (hbuf), NULL, 0, 0))
|
if (!getnameinfo((struct sockaddr *)&in6, slen, hbuf, sizeof (hbuf), NULL, 0, 0))
|
||||||
result = hbuf;
|
result = hbuf;
|
||||||
#else
|
|
||||||
struct hostent *host;
|
|
||||||
uint32_t addr;
|
|
||||||
|
|
||||||
switch (ip_addr->family) {
|
|
||||||
case IPADDR_INET4:
|
|
||||||
addr = htonl(ip_addr->addr.in4);
|
|
||||||
host = gethostbyaddr((const char *) &addr, sizeof (ip_addr), AF_INET);
|
|
||||||
break;
|
|
||||||
#ifdef FEAT_IPV6
|
|
||||||
case IPADDR_INET6:
|
|
||||||
host = gethostbyaddr((const void *) ip_addr->addr.in6, sizeof (ip_addr->addr.in6), AF_INET6);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
default:
|
|
||||||
host = NULL;
|
|
||||||
}
|
|
||||||
if (host)
|
|
||||||
result = host->h_name;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (result == NULL)
|
if (result == NULL)
|
||||||
result = UTI_IPToString(ip_addr);
|
result = UTI_IPToString(ip_addr);
|
||||||
|
|
Loading…
Reference in a new issue