]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxtables: xtables: Use getnameinfo()
authorShyam Saini <mayhs11saini@gmail.com>
Mon, 12 Dec 2016 14:53:57 +0000 (20:23 +0530)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 19 Dec 2016 23:36:38 +0000 (00:36 +0100)
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>
libxtables/xtables.c

index c5b38890832314079f9d468c8ac0119057be42c7..d43f97066ea9b71c21791e7f16de373162bf482c 100644 (file)
@@ -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)