diff --git a/CHANGES b/CHANGES index 3252df299..5e1b43791 100644 --- a/CHANGES +++ b/CHANGES @@ -55,6 +55,7 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group and use them rather than custom code Disregard setlinebuf(3), always use setvbuf(3). Change Sun RPC code licence to BSD-3-Clause. + Add support for no-capture and no-inject device flags. Building and testing: Autoconf: Remove detection of early IPv6 stacks. Detect OS IPv6 support using AF_INET6 only. diff --git a/tcpdump.1.in b/tcpdump.1.in index 0acb79eb8..318de0c8a 100644 --- a/tcpdump.1.in +++ b/tcpdump.1.in @@ -20,7 +20,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH TCPDUMP 1 "7 September 2024" +.TH TCPDUMP 1 "24 November 2024" .SH NAME tcpdump \- dump traffic on a network .SH SYNOPSIS @@ -348,13 +348,14 @@ Dump packet-matching code as decimal numbers (preceded with a count). .TP .B \-\-list\-interfaces .PD -Print the list of the network interfaces available on the system and on -which +Print the list of libpcap devices (regular and pseudo network interfaces, +802.11/Bluetooth/USB monitors, DAG/D-Bus/DPDK/netfilter/netmap/RDMA/SNF +devices etc.) available on the host on which .I tcpdump -can capture packets. For each network interface, a number and an -interface name, possibly followed by a text description of the -interface, are printed. The interface name or the number can be supplied -to the +is running. For each device print a name, a text description (if available) +and a set of flags. Also print a number unless libpcap indicates that the +device does not support packet capture. The interface name or the number +can be supplied to the .B \-i flag to specify an interface on which to capture. .IP diff --git a/tcpdump.c b/tcpdump.c index 56dc2145b..ba2c266c9 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -257,6 +257,12 @@ static const struct tok status_flags[] = { { PCAP_IF_LOOPBACK, "Loopback" }, #ifdef PCAP_IF_WIRELESS { PCAP_IF_WIRELESS, "Wireless" }, +#endif +#ifdef PCAP_IF_NO_INJECT + { PCAP_IF_NO_INJECT, "NoInject" }, +#endif +#ifdef PCAP_IF_NO_CAPTURE + { PCAP_IF_NO_CAPTURE, "NoCapture" }, #endif { 0, NULL } }; @@ -470,8 +476,25 @@ show_devices_and_exit(void) if (pcap_findalldevs(&devlist, ebuf) < 0) error("%s", ebuf); - for (i = 0, dev = devlist; dev != NULL; i++, dev = dev->next) { + for (i = 0, dev = devlist; dev != NULL; dev = dev->next) { + /* + * If PCAP_IF_NO_CAPTURE is set, do not count the device and + * print it without a number. + */ +#ifdef PCAP_IF_NO_CAPTURE + if (dev->flags & PCAP_IF_NO_CAPTURE) + printf("%s %s", + i > 999 ? " " : + i > 99 ? " " : + i > 9 ? " " : + " ", + dev->name + ); + else + printf("%d.%s", i+1, dev->name); +#else printf("%d.%s", i+1, dev->name); +#endif // PCAP_IF_NO_CAPTURE if (dev->description != NULL) printf(" (%s)", dev->description); if (dev->flags != 0) { @@ -519,6 +542,11 @@ show_devices_and_exit(void) printf("]"); } printf("\n"); +#ifdef PCAP_IF_NO_CAPTURE + if (dev->flags & PCAP_IF_NO_CAPTURE) + continue; +#endif // PCAP_IF_NO_CAPTURE + i++; } pcap_freealldevs(devlist); exit_tcpdump(S_SUCCESS); @@ -1172,10 +1200,18 @@ _U_ error("%s", ebuf); /* * Look for the devnum-th entry in the list of devices (1-based). + * Do not count devices that have PCAP_IF_NO_CAPTURE set, consistently + * with show_devices_and_exit(). */ - for (i = 0, dev = devlist; i < devnum-1 && dev != NULL; - i++, dev = dev->next) - ; + for (i = 0, dev = devlist; dev != NULL; dev = dev->next) { +#ifdef PCAP_IF_NO_CAPTURE + if (dev->flags & PCAP_IF_NO_CAPTURE) + continue; +#endif // PCAP_IF_NO_CAPTURE + if (i == devnum - 1) + break; + i++; + } if (dev == NULL) { pcap_freealldevs(devlist); error("Invalid adapter index %ld: only %ld interfaces found",