* [PATCH 1/2] libxtables: xtables: remove unnecessary debug code
@ 2016-12-12 14:53 Shyam Saini
2016-12-12 14:53 ` [PATCH 2/2] libxtables: xtables: Use getnameinfo() Shyam Saini
2016-12-19 23:37 ` [PATCH 1/2] libxtables: xtables: remove unnecessary debug code Pablo Neira Ayuso
0 siblings, 2 replies; 4+ messages in thread
From: Shyam Saini @ 2016-12-12 14:53 UTC (permalink / raw)
To: netfilter-devel; +Cc: Shyam Saini
Remove unnecessary debug code
Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
---
libxtables/xtables.c | 33 +++++----------------------------
1 file changed, 5 insertions(+), 28 deletions(-)
diff --git a/libxtables/xtables.c b/libxtables/xtables.c
index 921dfe9..6e75c15 100644
--- a/libxtables/xtables.c
+++ b/libxtables/xtables.c
@@ -1366,17 +1366,10 @@ static struct in_addr *host_to_ipaddr(const char *name, unsigned int *naddr)
*naddr = 0;
if ((err = getaddrinfo(name, NULL, &hints, &res)) != 0) {
-#ifdef DEBUG
- fprintf(stderr,"Name2IP: %s\n",gai_strerror(err));
-#endif
return NULL;
} else {
for (p = res; p != NULL; p = p->ai_next)
++*naddr;
-#ifdef DEBUG
- fprintf(stderr, "resolved: len=%d %s ", res->ai_addrlen,
- xtables_ipaddr_to_numeric(&((struct sockaddr_in *)res->ai_addr)->sin_addr));
-#endif
addr = xtables_calloc(*naddr, sizeof(struct in_addr));
for (i = 0, p = res; p != NULL; p = p->ai_next)
memcpy(&addr[i++],
@@ -1576,18 +1569,11 @@ static const char *ip6addr_to_host(const struct in6_addr *addr)
memcpy(&saddr.sin6_addr, addr, sizeof(*addr));
saddr.sin6_family = AF_INET6;
- err = getnameinfo((const void *)&saddr, sizeof(struct sockaddr_in6),
- hostname, sizeof(hostname) - 1, NULL, 0, 0);
- if (err != 0) {
-#ifdef DEBUG
- fprintf(stderr,"IP2Name: %s\n",gai_strerror(err));
-#endif
+ err = getnameinfo((const void *)&saddr, sizeof(struct sockaddr_in6),
+ hostname, sizeof(hostname) - 1, NULL, 0, 0);
+ if (err != 0)
return NULL;
- }
-
-#ifdef DEBUG
- fprintf (stderr, "\naddr2host: %s\n", hostname);
-#endif
+
return hostname;
}
@@ -1650,9 +1636,7 @@ struct in6_addr *xtables_numeric_to_ip6addr(const char *num)
if ((err = inet_pton(AF_INET6, num, &ap)) == 1)
return ≈
-#ifdef DEBUG
- fprintf(stderr, "\nnumeric2addr: %d\n", err);
-#endif
+
return NULL;
}
@@ -1672,18 +1656,11 @@ host_to_ip6addr(const char *name, unsigned int *naddr)
*naddr = 0;
if ((err = getaddrinfo(name, NULL, &hints, &res)) != 0) {
-#ifdef DEBUG
- fprintf(stderr,"Name2IP: %s\n",gai_strerror(err));
-#endif
return NULL;
} else {
/* Find length of address chain */
for (p = res; p != NULL; p = p->ai_next)
++*naddr;
-#ifdef DEBUG
- fprintf(stderr, "resolved: len=%d %s ", res->ai_addrlen,
- xtables_ip6addr_to_numeric(&((struct sockaddr_in6 *)res->ai_addr)->sin6_addr));
-#endif
/* Copy each element of the address chain */
addr = xtables_calloc(*naddr, sizeof(struct in6_addr));
for (i = 0, p = res; p != NULL; p = p->ai_next)
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] libxtables: xtables: Use getnameinfo()
2016-12-12 14:53 [PATCH 1/2] libxtables: xtables: remove unnecessary debug code Shyam Saini
@ 2016-12-12 14:53 ` Shyam Saini
2016-12-19 23:38 ` Pablo Neira Ayuso
2016-12-19 23:37 ` [PATCH 1/2] libxtables: xtables: remove unnecessary debug code Pablo Neira Ayuso
1 sibling, 1 reply; 4+ messages in thread
From: Shyam Saini @ 2016-12-12 14:53 UTC (permalink / raw)
To: netfilter-devel; +Cc: Shyam Saini
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>
---
libxtables/xtables.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/libxtables/xtables.c b/libxtables/xtables.c
index 6e75c15..e1512b1 100644
--- a/libxtables/xtables.c
+++ b/libxtables/xtables.c
@@ -1210,13 +1210,18 @@ 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, };
+ saddr.sin_addr = *addr;
+ int err;
- host = gethostbyaddr(addr, sizeof(struct in_addr), AF_INET);
- if (host == NULL)
- return NULL;
- return host->h_name;
+ err = getnameinfo((const void *)&saddr, sizeof(struct sockaddr_in),
+ hostname, sizeof(hostname) - 1, NULL, 0, 0);
+ if (err != 0)
+ return NULL;
+
+ return hostname;
}
static const char *ipaddr_to_network(const struct in_addr *addr)
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] libxtables: xtables: remove unnecessary debug code
2016-12-12 14:53 [PATCH 1/2] libxtables: xtables: remove unnecessary debug code Shyam Saini
2016-12-12 14:53 ` [PATCH 2/2] libxtables: xtables: Use getnameinfo() Shyam Saini
@ 2016-12-19 23:37 ` Pablo Neira Ayuso
1 sibling, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2016-12-19 23:37 UTC (permalink / raw)
To: Shyam Saini; +Cc: netfilter-devel
On Mon, Dec 12, 2016 at 08:23:56PM +0530, Shyam Saini wrote:
> Remove unnecessary debug code
Applied, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] libxtables: xtables: Use getnameinfo()
2016-12-12 14:53 ` [PATCH 2/2] libxtables: xtables: Use getnameinfo() Shyam Saini
@ 2016-12-19 23:38 ` Pablo Neira Ayuso
0 siblings, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2016-12-19 23:38 UTC (permalink / raw)
To: Shyam Saini; +Cc: netfilter-devel
On Mon, Dec 12, 2016 at 08:23:57PM +0530, Shyam Saini wrote:
> Replace gethostbyaddr() with getnameinfo() as getnameinfo()
> deprecates the former and allows programs to
> eliminate IPv4-versus-IPv6 dependencies
Also applied, thanks.
> Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
> ---
> libxtables/xtables.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/libxtables/xtables.c b/libxtables/xtables.c
> index 6e75c15..e1512b1 100644
> --- a/libxtables/xtables.c
> +++ b/libxtables/xtables.c
> @@ -1210,13 +1210,18 @@ 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, };
> + saddr.sin_addr = *addr;
diff --git a/libxtables/xtables.c b/libxtables/xtables.c
index bed43480d589..d43f97066ea9 100644
--- a/libxtables/xtables.c
+++ b/libxtables/xtables.c
@@ -1211,8 +1211,10 @@ const char *xtables_ipaddr_to_numeric(const
struct in_addr *addrp)
static const char *ipaddr_to_host(const struct in_addr *addr)
{
static char hostname[NI_MAXHOST];
- struct sockaddr_in saddr = { .sin_family = AF_INET, };
- saddr.sin_addr = *addr;
+ struct sockaddr_in saddr = {
+ .sin_family = AF_INET,
+ .sin_addr = *addr,
+ };
int err;
I collapsed this small update, so this is full C99 initialization.
Thanks.
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-12-19 23:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-12 14:53 [PATCH 1/2] libxtables: xtables: remove unnecessary debug code Shyam Saini
2016-12-12 14:53 ` [PATCH 2/2] libxtables: xtables: Use getnameinfo() Shyam Saini
2016-12-19 23:38 ` Pablo Neira Ayuso
2016-12-19 23:37 ` [PATCH 1/2] libxtables: xtables: remove unnecessary debug code Pablo Neira Ayuso
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.