From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pablo Neira Ayuso Subject: Re: [PATCH] libxtables: xtables.c: Use getnameinfo() Date: Sun, 11 Dec 2016 21:05:16 +0100 Message-ID: <20161211200516.GA11702@salvia> References: <1481284200-6104-1-git-send-email-mayhs11saini@gmail.com> <20161211200226.GA11648@salvia> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: netfilter-devel@vger.kernel.org To: Shyam Saini Return-path: Received: from mail.us.es ([193.147.175.20]:41720 "EHLO mail.us.es" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753804AbcLKUFY (ORCPT ); Sun, 11 Dec 2016 15:05:24 -0500 Received: from antivirus1-rhel7.int (unknown [192.168.2.11]) by mail.us.es (Postfix) with ESMTP id 2831F7FC4C for ; Sun, 11 Dec 2016 21:05:23 +0100 (CET) Received: from antivirus1-rhel7.int (localhost [127.0.0.1]) by antivirus1-rhel7.int (Postfix) with ESMTP id 183BDDA392 for ; Sun, 11 Dec 2016 21:05:23 +0100 (CET) Received: from antivirus1-rhel7.int (localhost [127.0.0.1]) by antivirus1-rhel7.int (Postfix) with ESMTP id 06FE5DA388 for ; Sun, 11 Dec 2016 21:05:21 +0100 (CET) Content-Disposition: inline In-Reply-To: <20161211200226.GA11648@salvia> Sender: netfilter-devel-owner@vger.kernel.org List-ID: On Sun, Dec 11, 2016 at 09:02:26PM +0100, Pablo Neira Ayuso wrote: > On Fri, Dec 09, 2016 at 05:20:00PM +0530, Shyam Saini wrote: > > Use getnameinfo() instead of deprecated gethostbyaddr() > > > > Signed-off-by: Shyam Saini > > --- > > 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)); > > You can skip this by perfoming C99 initialization, eg. > > struct sockaddr_in sin = { .sin_family = AF_INET, }; > sin.sin_addr = *addr; One more comment below. > > + 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 I don't remember to have used this debugging this ever, probably it is good to remove it. > > + return NULL; > > + } > > > > - return host->h_name; > > +#ifdef DEBUG > > + fprintf (stderr, "\naddr2host: %s\n", hostname); > > +#endif > > + return hostname; ^^^^^^^^^^^ Minor nitpick: indentation is not correct here.