aboutsummaryrefslogtreecommitdiff
path: root/pcap-usb-linux.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2022-06-03 18:00:22 -0700
committerGuy Harris <gharris@sonic.net>2022-06-03 18:00:41 -0700
commit08ab69f4fc5d432eb7de26ee8e33b40ea4b79744 (patch)
treeeff06cc3da09aa6a2a15832c724eaed00ff7b15d /pcap-usb-linux.c
parent04244a1b51e76981c0796c8f96e36827f7f2019c (diff)
Linux USB: fix incorrect values for the packet length.
Correctly compute the "real" length for isochronous transfers. When reading memory-mapped Linux capture files, fix up the "real" length field, in case the file was written by a program doing a capture with the bug.
Diffstat (limited to 'pcap-usb-linux.c')
-rw-r--r--pcap-usb-linux.c28
1 files changed, 9 insertions, 19 deletions
diff --git a/pcap-usb-linux.c b/pcap-usb-linux.c
index d62f17dd..ef495bd2 100644
--- a/pcap-usb-linux.c
+++ b/pcap-usb-linux.c
@@ -39,6 +39,7 @@
#include "pcap-int.h"
#include "pcap-usb-linux.h"
+#include "pcap-usb-linux-common.h"
#include "pcap/usb.h"
#include "extract.h"
@@ -756,6 +757,7 @@ usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_ch
struct mon_bin_mfetch fetch;
int32_t vec[VEC_SIZE];
struct pcap_pkthdr pkth;
+ u_char *bp;
pcap_usb_header_mmapped* hdr;
int nflush = 0;
int packets = 0;
@@ -839,8 +841,13 @@ usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_ch
* packets if we break out of the loop here.
*/
+ /* Get a pointer to this packet's buffer */
+ bp = &handlep->mmapbuf[vec[i]];
+
+ /* That begins with a metadata header */
+ hdr = (pcap_usb_header_mmapped*) bp;
+
/* discard filler */
- hdr = (pcap_usb_header_mmapped*) &handlep->mmapbuf[vec[i]];
if (hdr->event_type == '@')
continue;
@@ -868,24 +875,7 @@ usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_ch
if (hdr->data_len < clen)
clen = hdr->data_len;
pkth.caplen = sizeof(pcap_usb_header_mmapped) + clen;
- if (hdr->data_flag) {
- /*
- * No data; just base the on-the-wire length
- * on hdr->data_len (so that it's >= the
- * captured length).
- */
- pkth.len = sizeof(pcap_usb_header_mmapped) +
- hdr->data_len;
- } else {
- /*
- * We got data; base the on-the-wire length
- * on hdr->urb_len, so that it includes
- * data discarded by the USB monitor device
- * due to its buffer being too small.
- */
- pkth.len = sizeof(pcap_usb_header_mmapped) +
- (hdr->ndesc * sizeof (usb_isodesc)) + hdr->urb_len;
- }
+ set_linux_usb_mmapped_length(&pkth, bp);
pkth.ts.tv_sec = (time_t)hdr->ts_sec;
pkth.ts.tv_usec = hdr->ts_usec;