From: lantw44@gmail.com
To: netfilter-devel@vger.kernel.org
Cc: Ting-Wei Lan <lantw44@gmail.com>
Subject: [PATCH 1/3] extra: use inet_ntop instead of inet_ntoa
Date: Fri, 20 Jun 2014 18:26:59 +0800 [thread overview]
Message-ID: <1403260021-8732-1-git-send-email-lantw44@gmail.com> (raw)
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.
---
| 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
--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
next reply other threads:[~2014-06-20 10:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-20 10:26 lantw44 [this message]
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
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=1403260021-8732-1-git-send-email-lantw44@gmail.com \
--to=lantw44@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).