netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libxtables: xtables.c: Use getnameinfo()
@ 2016-12-09 11:50 Shyam Saini
  2016-12-11 20:02 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 5+ messages in thread
From: Shyam Saini @ 2016-12-09 11:50 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Shyam Saini

Use getnameinfo() instead of deprecated gethostbyaddr()

Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
---
 libxtables/xtables.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/libxtables/xtables.c b/libxtables/xtables.c
index 921dfe9..338e325 100644
--- a/libxtables/xtables.c
+++ b/libxtables/xtables.c
@@ -1210,13 +1210,28 @@ 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;
+	int err;
 
-	host = gethostbyaddr(addr, sizeof(struct in_addr), AF_INET);
-	if (host == NULL)
-		return NULL;
+	memset(&saddr, 0, sizeof(struct sockaddr_in));
+	memcpy(&saddr.sin_addr, addr, sizeof(*addr));
+	saddr.sin_family = AF_INET;
+
+	err = getnameinfo((const void *)&saddr, sizeof(struct sockaddr_in),
+			              hostname, sizeof(hostname) - 1, NULL, 0, 0);
+
+	 if (err != 0) {
+#ifdef DEBUG
+		 fprintf(stderr,"IP2Name: %s\n",gai_strerror(err));
+#endif
+		 return NULL;
+	}
 
-	return host->h_name;
+#ifdef DEBUG
+		fprintf (stderr, "\naddr2host: %s\n", hostname);
+#endif
+		return hostname;
 }
 
 static const char *ipaddr_to_network(const struct in_addr *addr)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-12-11 20:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-09 11:50 [PATCH] libxtables: xtables.c: Use getnameinfo() Shyam Saini
2016-12-11 20:02 ` Pablo Neira Ayuso
2016-12-11 20:05   ` Pablo Neira Ayuso
2016-12-11 20:17     ` Shivani Bhardwaj
2016-12-11 20:25       ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).