From 77db569dcd5ba07309c73624542bd802598c2690 Mon Sep 17 00:00:00 2001 From: Shyam Saini Date: Mon, 12 Dec 2016 20:23:57 +0530 Subject: libxtables: xtables: Use getnameinfo() Replace gethostbyaddr() with getnameinfo() as getnameinfo() deprecates the former and allows programs to eliminate IPv4-versus-IPv6 dependencies Signed-off-by: Shyam Saini Signed-off-by: Pablo Neira Ayuso --- libxtables/xtables.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'libxtables') diff --git a/libxtables/xtables.c b/libxtables/xtables.c index c5b38890..d43f9706 100644 --- a/libxtables/xtables.c +++ b/libxtables/xtables.c @@ -1210,13 +1210,20 @@ const char *xtables_ipaddr_to_numeric(const struct in_addr *addrp) static const char *ipaddr_to_host(const struct in_addr *addr) { - struct hostent *host; + static char hostname[NI_MAXHOST]; + struct sockaddr_in saddr = { + .sin_family = AF_INET, + .sin_addr = *addr, + }; + int err; - host = gethostbyaddr(addr, sizeof(struct in_addr), AF_INET); - if (host == NULL) + + err = getnameinfo((const void *)&saddr, sizeof(struct sockaddr_in), + hostname, sizeof(hostname) - 1, NULL, 0, 0); + if (err != 0) return NULL; - return host->h_name; + return hostname; } static const char *ipaddr_to_network(const struct in_addr *addr) -- cgit v1.2.3