From: Guy Harris Date: Wed, 7 Jun 2023 02:56:17 +0000 (-0700) Subject: Ignore failures when setting the default "any" device DLL to LINUX_SLL2. X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/c6b4ee68786c76d47327944e9f3be779bcfe4c6e 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. --- diff --git a/tcpdump.c b/tcpdump.c index b0d3aa5b..8b00cdd1 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -2029,14 +2029,6 @@ main(int argc, char **argv) show_remote_devices_and_exit(); #endif -#if defined(DLT_LINUX_SLL2) && defined(HAVE_PCAP_SET_DATALINK) -/* Set default linktype DLT_LINUX_SLL2 when capturing on the "any" device */ - if (device != NULL && - strncmp (device, "any", strlen("any")) == 0 - && yflag_dlt == -1) - yflag_dlt = DLT_LINUX_SLL2; -#endif - switch (ndo->ndo_tflag) { case 0: /* Default */ @@ -2289,6 +2281,21 @@ main(int argc, char **argv) pcap_datalink_val_to_name(yflag_dlt)); (void)fflush(stderr); } +#if defined(DLT_LINUX_SLL2) && defined(HAVE_PCAP_SET_DATALINK) + else { + /* + * Attempt to set default linktype to + * DLT_LINUX_SLL2 when capturing on the + * "any" device. + * + * If the attempt fails, just quietly drive + * on; this may be a non-Linux "any" device + * that doesn't support DLT_LINUX_SLL2. + */ + if (strcmp(device, "any") == 0) + (void) pcap_set_datalink(pd, DLT_LINUX_SLL2); + } +#endif i = pcap_snapshot(pd); if (ndo->ndo_snaplen < i) { if (ndo->ndo_snaplen != 0)