All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] extra: use inet_ntop instead of inet_ntoa
@ 2014-06-20 10:26 lantw44
  2014-06-20 10:27 ` [PATCH 2/3] extra: fix wrong implementation in nfq_udp_get_payload lantw44
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: lantw44 @ 2014-06-20 10:26 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Ting-Wei Lan

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(-)

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);
-- 
1.9.3


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

end of thread, other threads:[~2014-06-30 17:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-20 10:26 [PATCH 1/3] extra: use inet_ntop instead of inet_ntoa lantw44
2014-06-20 10:27 ` [PATCH 2/3] extra: fix wrong implementation in nfq_udp_get_payload lantw44
2014-06-30 10:02   ` Pablo Neira Ayuso
2014-06-30 17:00     ` 藍挺瑋
2014-06-20 10:27 ` [PATCH 3/3] extra: fix wrong implementation in nfq_udp_get_payload_len lantw44
2014-06-30 10:11   ` Pablo Neira Ayuso
2014-06-30  9:48 ` [PATCH 1/3] extra: use inet_ntop instead of inet_ntoa 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.