Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(do not merge yet) Add support for no-capture and no-inject device flags. #1246

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 8 additions & 7 deletions tcpdump.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
44 changes: 40 additions & 4 deletions tcpdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
};
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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",
Expand Down