summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw44@gmail.com>2014-06-20 18:26:59 +0800
committerPablo Neira Ayuso <pablo@netfilter.org>2014-06-30 11:47:02 +0200
commit3065fb3642c8e554432059629808a62560e2184f (patch)
tree34041b92de488827e5bfb9ebcc117a55c9926cc0
parent862c4ff36336efe4824602cdf141d459f024dc74 (diff)
extra: use inet_ntop instead of inet_ntoa
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. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--src/extra/ipv4.c6
1 files changed, 5 insertions, 1 deletions
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);