pcapparse: Fix handling of TCP payload length
authorOleksandrKvl <oleksandrdvl@gmail.com>
Mon, 24 Jun 2019 15:39:35 +0000 (18:39 +0300)
committerSebastian Dröge <slomo@coaxion.net>
Mon, 24 Jun 2019 15:55:38 +0000 (15:55 +0000)
The length of the  TCP payload is the IP plus TCP header length
subtracted from the IP datagram length specified in the IP header.
Prior to this, the size was calculated incorrectly, considering
all data after TCP header as a payload till the end of a packet.

Fixes #995

gst/pcapparse/gstpcapparse.c

index 0670407..3ea656b 100644 (file)
@@ -374,6 +374,7 @@ gst_pcap_parse_scan_frame (GstPcapParse * self,
   guint16 src_port;
   guint16 dst_port;
   guint16 len;
+  guint16 ip_packet_len;
 
   switch (self->linktype) {
     case LINKTYPE_ETHER:
@@ -448,6 +449,7 @@ gst_pcap_parse_scan_frame (GstPcapParse * self,
   ip_src_addr = *((guint32 *) (buf_ip + 12));
   ip_dst_addr = *((guint32 *) (buf_ip + 16));
   buf_proto = buf_ip + ip_header_size;
+  ip_packet_len = GUINT16_FROM_BE (*(guint16 *) (buf_ip + 2));
 
   /* ok for tcp and udp */
   src_port = GUINT16_FROM_BE (*((guint16 *) (buf_proto + 0)));
@@ -470,7 +472,7 @@ gst_pcap_parse_scan_frame (GstPcapParse * self,
 
     /* all remaining data following tcp header is payload */
     *payload = buf_proto + len;
-    *payload_size = self->cur_packet_size - (buf_proto - buf) - len;
+    *payload_size = ip_packet_len - ip_header_size - len;
   }
 
   /* but still filter as configured */