[commits] [batctl] next: batctl tcpdump: Fix reported length of TCP payload (e374a3f)

postmaster at open-mesh.org postmaster at open-mesh.org
Wed Sep 25 16:49:37 CEST 2013


Repository : ssh://git@open-mesh.org/batctl

On branch  : next

>---------------------------------------------------------------

commit e374a3fe9b40903591ba8049195fb9327a086ea9
Author: Marco Dalla Torre <marco.dallato at gmail.com>
Date:   Sat Sep 21 17:05:07 2013 +0200

    batctl tcpdump: Fix reported length of TCP payload
    
    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 at gmail.com>
    Signed-off-by: Marek Lindner <mareklindner at neomailbox.ch>


>---------------------------------------------------------------

e374a3fe9b40903591ba8049195fb9327a086ea9
 tcpdump.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tcpdump.c b/tcpdump.c
index a220c3c..8f39ac0 100644
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -198,6 +198,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");
@@ -261,16 +262,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");



More information about the commits mailing list