public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Marco Dalla Torre <marco.dallato@gmail.com>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCH maint] batctl tcpdump: Fix reported length of TCP payload
Date: Sat, 21 Sep 2013 17:05:07 +0200	[thread overview]
Message-ID: <1379775907-19199-1-git-send-email-marco.dallato@gmail.com> (raw)

Fixes the erratic report of TCP payload length in 'batctl tcpdump'.
Previously TCP header length size was considered fixed, while
this is actually not the case given the variable length (or no
presence at all) of the options field.

Signed-off-by: Marco Dalla Torre <marco.dallato@gmail.com>
---
 tcpdump.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tcpdump.c b/tcpdump.c
index 7e0987b..e6f8f7d 100644
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -194,6 +194,7 @@ static void dump_ip(unsigned char *packet_buff, ssize_t buff_len, int time_print
 	struct tcphdr *tcphdr;
 	struct udphdr *udphdr, *tmp_udphdr;
 	struct icmphdr *icmphdr;
+	uint16_t tcp_header_len;
 
 	iphdr = (struct iphdr *)packet_buff;
 	LEN_CHECK((size_t)buff_len, (size_t)(iphdr->ihl * 4), "IP");
@@ -257,16 +258,18 @@ static void dump_ip(unsigned char *packet_buff, ssize_t buff_len, int time_print
 
 		break;
 	case IPPROTO_TCP:
-		LEN_CHECK((size_t)buff_len - (iphdr->ihl * 4), sizeof(struct tcphdr), "TCP");
-
 		tcphdr = (struct tcphdr *)(packet_buff + (iphdr->ihl * 4));
+		tcp_header_len = tcphdr->doff * 4;
+		LEN_CHECK((size_t)buff_len - (iphdr->ihl * 4),
+			  (size_t)tcp_header_len, "TCP");
+
 		printf("IP %s.%i > ", inet_ntoa(*(struct in_addr *)&iphdr->saddr), ntohs(tcphdr->source));
 		printf("%s.%i: TCP, flags [%c%c%c%c%c%c], length %zu\n",
 			inet_ntoa(*(struct in_addr *)&iphdr->daddr), ntohs(tcphdr->dest),
 			(tcphdr->fin ? 'F' : '.'), (tcphdr->syn ? 'S' : '.'),
 			(tcphdr->rst ? 'R' : '.'), (tcphdr->psh ? 'P' : '.'),
 			(tcphdr->ack ? 'A' : '.'), (tcphdr->urg ? 'U' : '.'),
-			(size_t)buff_len - (iphdr->ihl * 4) - sizeof(struct tcphdr));
+			(size_t)buff_len - (iphdr->ihl * 4) - tcp_header_len);
 		break;
 	case IPPROTO_UDP:
 		LEN_CHECK((size_t)buff_len - (iphdr->ihl * 4), sizeof(struct udphdr), "UDP");
-- 
1.8.3.2


             reply	other threads:[~2013-09-21 15:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-21 15:05 Marco Dalla Torre [this message]
2013-09-25 14:49 ` [B.A.T.M.A.N.] [PATCH maint] batctl tcpdump: Fix reported length of TCP payload Marek Lindner

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=1379775907-19199-1-git-send-email-marco.dallato@gmail.com \
    --to=marco.dallato@gmail.com \
    --cc=b.a.t.m.a.n@lists.open-mesh.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