Skip to content

Commit 2efb9e6

Browse files
committed
Make the "Invalid adapter index" look better with 0 or 1 interface.
If *no* interfaces were found, just say "no interfaces available for capture", as we do if no -i flag was specified and there aren't any interfaces. Otherwise, say "interface" rathr than "interfaces" if there's only one. Show that and another message in the CHANGES section for changes backported to 4.99.
1 parent 21e664b commit 2efb9e6

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
116116
Update the -z option processing. Print "invalid option -- z" when it is.
117117
Other:
118118
Avoid race condition when receiving signal during shutdown.
119+
Always show the interface name in error messages when the
120+
interface can't be opened.
121+
Clean up the message shown if a -i flag is specified with an
122+
interface index that's too large.
119123
Source code:
120124
Fix '-tt' option printing when time > 2106-02-07T06:28:15Z.
121125
Add sub-second packet timestamp checks for invalid micro/nano.

tcpdump.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,8 @@ _U_
11981198
status = pcap_findalldevs(&devlist, ebuf);
11991199
if (status < 0)
12001200
error("%s", ebuf);
1201+
if (devlist == NULL)
1202+
error("no interfaces available for capture");
12011203
/*
12021204
* Look for the devnum-th entry in the list of devices (1-based).
12031205
*/
@@ -1206,8 +1208,8 @@ _U_
12061208
;
12071209
if (dev == NULL) {
12081210
pcap_freealldevs(devlist);
1209-
error("Invalid adapter index %ld: only %ld interfaces found",
1210-
devnum, i);
1211+
error("Invalid adapter index %ld: only %ld interface%s found",
1212+
devnum, i, (i == 1) ? "" : "s");
12111213
}
12121214
device = strdup(dev->name);
12131215
pcap_freealldevs(devlist);

0 commit comments

Comments
 (0)