public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [PATCH maint] batctl tcpdump: Fix reported length of TCP payload
@ 2013-09-21 15:05 Marco Dalla Torre
  2013-09-25 14:49 ` Marek Lindner
  0 siblings, 1 reply; 2+ messages in thread
From: Marco Dalla Torre @ 2013-09-21 15:05 UTC (permalink / raw)
  To: b.a.t.m.a.n

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


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

* Re: [B.A.T.M.A.N.] [PATCH maint] batctl tcpdump: Fix reported length of TCP payload
  2013-09-21 15:05 [B.A.T.M.A.N.] [PATCH maint] batctl tcpdump: Fix reported length of TCP payload Marco Dalla Torre
@ 2013-09-25 14:49 ` Marek Lindner
  0 siblings, 0 replies; 2+ messages in thread
From: Marek Lindner @ 2013-09-25 14:49 UTC (permalink / raw)
  To: b.a.t.m.a.n

[-- Attachment #1: Type: text/plain, Size: 497 bytes --]

On Saturday 21 September 2013 17:05:07 Marco Dalla Torre wrote:
> 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(-)

Applied in revision e374a3f.

Thanks,
Marek

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 490 bytes --]

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

end of thread, other threads:[~2013-09-25 14:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-21 15:05 [B.A.T.M.A.N.] [PATCH maint] batctl tcpdump: Fix reported length of TCP payload Marco Dalla Torre
2013-09-25 14:49 ` Marek Lindner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox