The branch main has been updated by kevans:

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

commit 87fb416ac8828d07fdf23a2c0d35d88efafce2af
Author:     Kyle Evans <[email protected]>
AuthorDate: 2026-07-12 19:50:24 +0000
Commit:     Kyle Evans <[email protected]>
CommitDate: 2026-07-12 19:50: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
    Differential Revision:  https://reviews.freebsd.org/D58196
---
 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 d7b084657162..36b70d3160bd 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");
@@ -811,7 +817,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':
@@ -881,6 +887,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);

Reply via email to