git: a76cac3a2062 - stable/15 - usbdump: add -t to omit timestamps

Kyle Evans <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a753960.3ae9c.55db1a76__40064.2931622983$1786067407$gmane$org@gitrepo.freebsd.org>
The branch stable/15 has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=a76cac3a2062d4be107b4dabda0fcdedf71db340

commit a76cac3a2062d4be107b4dabda0fcdedf71db340
Author:     Kyle Evans <[email protected]>
AuthorDate: 2026-07-12 19:50:24 +0000
Commit:     Kyle Evans <[email protected]>
CommitDate: 2026-08-06 23:36:24 +0000

    usbdump: add -t to omit timestamps
    
    Matches tcpdump naming, but without getting more intense as you add more
    -t.  This slightly reduces the post-processing needed on usbdump output
    to diff two transactions.
    
    Reviewed by:    adrian
    
    (cherry picked from commit 87fb416ac8828d07fdf23a2c0d35d88efafce2af)
---
 usr.sbin/usbdump/usbdump.8 |  9 +++++++--
 usr.sbin/usbdump/usbdump.c | 35 ++++++++++++++++++++++-------------
 2 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/usr.sbin/usbdump/usbdump.8 b/usr.sbin/usbdump/usbdump.8
index 96be9f738e2d..3c50f54d081e 100644
--- a/usr.sbin/usbdump/usbdump.8
+++ b/usr.sbin/usbdump/usbdump.8
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd May 14, 2021
+.Dd July 12, 2026
 .Dt USBDUMP 8
 .Os
 .Sh NAME
@@ -37,6 +37,7 @@
 .Op Fl i Ar ifname
 .Op Fl r Ar file
 .Op Fl s Ar snaplen
+.Op Fl t
 .Op Fl u
 .Op Fl v
 .Op Fl w Ar file
@@ -90,6 +91,8 @@ This option also works with the -f option.
 Snapshot
 .Ar snaplen
 bytes from each packet.
+.It Fl t
+Do not print packet timestamps.
 .It Fl u
 Unbuffered output.
 .It Fl v
@@ -140,7 +143,9 @@ is as follows:
 The meaning of the output format elements is as follows:
 .Bl -tag -width "<xfertype>"
 .It <time>
-A timestamp preceding all output lines.
+A timestamp preceding all output lines, unless the
+.Fl t
+option is used.
 The timestamp has the format "hh:mm:ss.frac" and is as accurate as
 the kernel's clock.
 .It <bus>
diff --git a/usr.sbin/usbdump/usbdump.c b/usr.sbin/usbdump/usbdump.c
index 887e2baeed26..519fa1c5266e 100644
--- a/usr.sbin/usbdump/usbdump.c
+++ b/usr.sbin/usbdump/usbdump.c
@@ -45,6 +45,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -108,6 +109,7 @@ struct header_32 {
 
 static int doexit;
 static int pkt_captured;
+static bool print_time = true;
 static int verbose;
 static int uf_minor;
 static char *i_arg;
@@ -459,13 +461,9 @@ hexdump(const uint8_t *region, uint32_t len)
 static void
 print_apacket(const struct header_32 *hdr, const uint8_t *ptr, int ptr_len)
 {
-	struct tm *tm;
 	struct usbpf_pkthdr up_temp;
 	struct usbpf_pkthdr *up;
-	struct timeval tv;
-	size_t len;
 	uint32_t x;
-	char buf[64];
 
 	ptr += USBPF_HDR_LEN;
 	ptr_len -= USBPF_HDR_LEN;
@@ -494,15 +492,22 @@ print_apacket(const struct header_32 *hdr, const uint8_t *ptr, int ptr_len)
 	if (!match_filter(up->up_address, up->up_endpoint))
 		return;
 
-	tv.tv_sec = hdr->ts_sec;
-	tv.tv_usec = hdr->ts_usec;
-	tm = localtime(&tv.tv_sec);
-
-	len = strftime(buf, sizeof(buf), "%H:%M:%S", tm);
-
 	if (verbose >= 0) {
-		printf("%.*s.%06ld usbus%d.%d %s-%s-EP=%08x,SPD=%s,NFR=%d,SLEN=%d,IVAL=%d%s%s\n",
-		    (int)len, buf, tv.tv_usec,
+		if (print_time) {
+			struct timeval tv;
+			char buf[64];
+			struct tm *tm;
+			size_t len;
+
+			tv.tv_sec = hdr->ts_sec;
+			tv.tv_usec = hdr->ts_usec;
+			tm = localtime(&tv.tv_sec);
+
+			len = strftime(buf, sizeof(buf), "%H:%M:%S", tm);
+			printf("%.*s.%06ld ", (int)len, buf, tv.tv_usec);
+		}
+
+		printf("usbus%d.%d %s-%s-EP=%08x,SPD=%s,NFR=%d,SLEN=%d,IVAL=%d%s%s\n",
 		    (int)up->up_busunit, (int)up->up_address,
 		    (up->up_type == USBPF_XFERTAP_SUBMIT) ? "SUBM" : "DONE",
 		    usb_xferstr(up->up_xfertype),
@@ -784,6 +789,7 @@ usage(void)
 	fprintf(stderr, FMT, "-f <unit[.endpoint]>", "Specify a device and endpoint filter");
 	fprintf(stderr, FMT, "-r <file>", "Read the raw packets from file");
 	fprintf(stderr, FMT, "-s <snaplen>", "Snapshot bytes from each packet");
+	fprintf(stderr, FMT, "-t", "Do not print packet timestamps");
 	fprintf(stderr, FMT, "-v", "Increase the verbose level");
 	fprintf(stderr, FMT, "-b <file>", "Save raw version of all recorded data to file");
 	fprintf(stderr, FMT, "-w <file>", "Write the raw packets to file");
@@ -829,7 +835,7 @@ main(int argc, char *argv[])
 	const char *optstring;
 	char *pp;
 
-	optstring = "b:d:hi:r:s:uvw:f:";
+	optstring = "b:d:hi:r:s:tuvw:f:";
 	while ((o = getopt(argc, argv, optstring)) != -1) {
 		switch (o) {
 		case 'b':
@@ -899,6 +905,9 @@ main(int argc, char *argv[])
 			if (snapshot == 0)
 				snapshot = -1;
 			break;
+		case 't':
+			print_time = false;
+			break;
 		case 'u':
 			setbuf(stdout, NULL);
 			setbuf(stderr, NULL);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.