From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Shyam Saini <mayhs11saini@gmail.com>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH] libxtables: xtables.c: Use getnameinfo()
Date: Sun, 11 Dec 2016 21:05:16 +0100 [thread overview]
Message-ID: <20161211200516.GA11702@salvia> (raw)
In-Reply-To: <20161211200226.GA11648@salvia>
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 <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));
>
> 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.
next prev parent reply other threads:[~2016-12-11 20:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2016-12-11 20:17 ` Shivani Bhardwaj
2016-12-11 20:25 ` Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161211200516.GA11702@salvia \
--to=pablo@netfilter.org \
--cc=mayhs11saini@gmail.com \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.