From b9df870da1f0f6983fe212a85bead683c39ec8a2 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sat, 21 Sep 2019 20:53:36 +0200 Subject: Add -c to output only control packets --- usbdump.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/usbdump.c b/usbdump.c index a825c65..6558663 100644 --- a/usbdump.c +++ b/usbdump.c @@ -40,6 +40,7 @@ #define LINEBUF_LEN 16383 int opt_unique_num = 0; +int opt_control_only = 0; int64_t start_ts = 0; int32_t start_ts_us = 0; @@ -211,6 +212,9 @@ void usb_sniff(int bus, int address) if (hdr->busnum != bus || hdr->devnum != address) /* some other device */ continue; + if (opt_control_only && hdr->xfer_type != XFER_TYPE_CONTROL) + /* not a control transfer */ + continue; process_packet(hdr, &mbuf[vec[i]]+sizeof(struct usbmon_packet)); } @@ -297,7 +301,7 @@ void usage(void) { printf("usbdump Copyright (C) 2011 Bert Vermeulen \n"); - printf("usage: usbdump -d [-u ]\n"); + printf("usage: usbdump -d [-u ] [-c]\n"); } @@ -307,7 +311,7 @@ int main(int argc, char **argv) char *device, *entry; device = NULL; - while ((opt = getopt(argc, argv, "d:u:")) != -1) { + while ((opt = getopt(argc, argv, "d:u:c")) != -1) { switch (opt) { case 'd': if (strlen(optarg) != 9 || strspn(optarg, "01234567890abcdef:") != 9) @@ -318,6 +322,9 @@ int main(int argc, char **argv) case 'u': opt_unique_num = strtol(optarg, NULL, 10); break; + case 'c': + opt_control_only = 1; + break; } } -- cgit v1.2.3