diff mbox

[1/3] extra: use inet_ntop instead of inet_ntoa

Message ID 1403260021-8732-1-git-send-email-lantw44@gmail.com
State Accepted
Headers show

Commit Message

lantw44@gmail.com June 20, 2014, 10:26 a.m. UTC
From: Ting-Wei Lan <lantw44@gmail.com>

The result of inet_ntoa() will be overwritten by the next call to
inet_ntoa(), so using it twice in the same snprintf() call causes
wrong result.
---
 src/extra/ipv4.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Pablo Neira Ayuso June 30, 2014, 9:48 a.m. UTC | #1
On Fri, Jun 20, 2014 at 06:26:59PM +0800, lantw44@gmail.com wrote:
> From: Ting-Wei Lan <lantw44@gmail.com>
> 
> The result of inet_ntoa() will be overwritten by the next call to
> inet_ntoa(), so using it twice in the same snprintf() call causes
> wrong result.

Applied, thanks Lan.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/src/extra/ipv4.c b/src/extra/ipv4.c
index 0fe716b..a93d113 100644
--- a/src/extra/ipv4.c
+++ b/src/extra/ipv4.c
@@ -134,9 +134,13 @@  int nfq_ip_snprintf(char *buf, size_t size, const struct iphdr *iph)
 	struct in_addr src = { iph->saddr };
 	struct in_addr dst = { iph->daddr };
 
+	char src_str[INET_ADDRSTRLEN];
+	char dst_str[INET_ADDRSTRLEN];
+
 	ret = snprintf(buf, size, "SRC=%s DST=%s LEN=%u TOS=0x%X "
 				  "PREC=0x%X TTL=%u ID=%u PROTO=%u ",
-			inet_ntoa(src), inet_ntoa(dst),
+			inet_ntop(AF_INET, &src, src_str, INET_ADDRSTRLEN),
+			inet_ntop(AF_INET, &dst, dst_str, INET_ADDRSTRLEN),
 			ntohs(iph->tot_len), IPTOS_TOS(iph->tos),
 			IPTOS_PREC(iph->tos), iph->ttl, ntohs(iph->id),
 			iph->protocol);