Skip to content

Commit c6b4ee6

Browse files
committed
Ignore failures when setting the default "any" device DLL to LINUX_SLL2.
If the user didn't explicitly request DLT_LINUX_SLL2 with -y, attempt to set the link-layer type on the "any" device to DLT_LINUX_SLL2, but, if that fails, just drive on - it could be the Solaris or macOS "any" device, neither of which support the Linux-style headers, or it could be a tcpdump built with a newer libpcap but dynamically-linked, and running on a system with an older libpcap that doesn't support DLT_LINUX_SLL2. Fixes #1057.
1 parent 10f7dff commit c6b4ee6

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

tcpdump.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,14 +2029,6 @@ main(int argc, char **argv)
20292029
show_remote_devices_and_exit();
20302030
#endif
20312031

2032-
#if defined(DLT_LINUX_SLL2) && defined(HAVE_PCAP_SET_DATALINK)
2033-
/* Set default linktype DLT_LINUX_SLL2 when capturing on the "any" device */
2034-
if (device != NULL &&
2035-
strncmp (device, "any", strlen("any")) == 0
2036-
&& yflag_dlt == -1)
2037-
yflag_dlt = DLT_LINUX_SLL2;
2038-
#endif
2039-
20402032
switch (ndo->ndo_tflag) {
20412033

20422034
case 0: /* Default */
@@ -2289,6 +2281,21 @@ main(int argc, char **argv)
22892281
pcap_datalink_val_to_name(yflag_dlt));
22902282
(void)fflush(stderr);
22912283
}
2284+
#if defined(DLT_LINUX_SLL2) && defined(HAVE_PCAP_SET_DATALINK)
2285+
else {
2286+
/*
2287+
* Attempt to set default linktype to
2288+
* DLT_LINUX_SLL2 when capturing on the
2289+
* "any" device.
2290+
*
2291+
* If the attempt fails, just quietly drive
2292+
* on; this may be a non-Linux "any" device
2293+
* that doesn't support DLT_LINUX_SLL2.
2294+
*/
2295+
if (strcmp(device, "any") == 0)
2296+
(void) pcap_set_datalink(pd, DLT_LINUX_SLL2);
2297+
}
2298+
#endif
22922299
i = pcap_snapshot(pd);
22932300
if (ndo->ndo_snaplen < i) {
22942301
if (ndo->ndo_snaplen != 0)

0 commit comments

Comments
 (0)