summaryrefslogtreecommitdiffstats
path: root/libxtables
diff options
context:
space:
mode:
authorShyam Saini <mayhs11saini@gmail.com>2016-12-12 20:23:57 +0530
committerPablo Neira Ayuso <pablo@netfilter.org>2016-12-20 00:36:38 +0100
commit77db569dcd5ba07309c73624542bd802598c2690 (patch)
treea885af4cc4c3b4afc5dd40448889d9f594cc7f1a /libxtables
parent7f526c9373c177e2d465b2b0316bdf67c7e65b5a (diff)
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 <mayhs11saini@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'libxtables')
-rw-r--r--libxtables/xtables.c15
1 files changed, 11 insertions, 4 deletions
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)