From 08867c67796e8a564d228ea3b2ae3ea8d78378a4 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sun, 22 Sep 2019 01:50:21 +0200 Subject: Add -l to limit data dumped --- usbdump.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/usbdump.c b/usbdump.c index fd3358e..84ea108 100644 --- a/usbdump.c +++ b/usbdump.c @@ -40,6 +40,7 @@ #define LINEBUF_LEN 16383 int opt_unique_num = 0; +int opt_data_limit = -1; int opt_control_only = 0; int64_t start_ts = 0; @@ -62,7 +63,7 @@ void hexdump(char *linebuf, void *address, int length) n = strlen(linebuf); buf = address; - for (i = 0; i < length; i++) { + for (i = 0; i < length && (opt_data_limit == -1 || i < opt_data_limit); i++) { if (n > LINEBUF_LEN - 4) continue; if (i && !(i & 0x01)) { @@ -309,7 +310,7 @@ void usage(void) { printf("usbdump Copyright (C) 2011 Bert Vermeulen \n"); - printf("usage: usbdump -d [-u ] [-c]\n"); + printf("usage: usbdump -d [-u ] [-l ] [-c]\n"); } @@ -319,7 +320,7 @@ int main(int argc, char **argv) char *device, *entry; device = NULL; - while ((opt = getopt(argc, argv, "d:u:c")) != -1) { + while ((opt = getopt(argc, argv, "d:u:l:c")) != -1) { switch (opt) { case 'd': if (strlen(optarg) != 9 || strspn(optarg, "01234567890abcdef:") != 9) @@ -330,6 +331,9 @@ int main(int argc, char **argv) case 'u': opt_unique_num = strtol(optarg, NULL, 10); break; + case 'l': + opt_data_limit = strtol(optarg, NULL, 10); + break; case 'c': opt_control_only = 1; break; -- cgit v1.2.3