Skip to content

Packet-buffered mode (-U) doesn't affect packet printing #1213

Open
@GD1200

Description

@GD1200

I noticed that the packet-buffered mode (-U) has no effect when STDOUT is not a terminal and raw packets recording (-w) is not used. If my STDOUT is tee, the terminal gets updated only when tcpdump's output buffer is full. In the example below, 10 ICMP packets had already been captured but the output buffer was not full yet, so nothing was printed to the terminal:

$ sudo tcpdump -Uni wlan0 icmp | tee /dev/null
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on wlan0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
^C10 packets captured
10 packets received by filter
0 packets dropped by kernel

I understand that -U is primarily used in combination with -w, but the manual says that it can also be used without -w:

   -U
   --packet-buffered
          If the -w option is not specified, or if it is specified but the --print  flag
          is  also  specified, make the printed packet output ‘‘packet-buffered''; i.e.,
          as the description of the contents of each packet is printed, it will be writ‐
          ten to the standard output, rather than, when not writing to a terminal, being
          written only when the output buffer fills.

It was tested against the latest stable tcpdump and libpcap versions:

$ tcpdump --version
tcpdump version 4.99.4
libpcap version 1.10.4 (with TPACKET_V3)
OpenSSL 3.3.1 4 Jun 2024

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions