]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Ignore failures when setting the default "any" device DLL to LINUX_SLL2.
authorGuy Harris <[email protected]>
Wed, 7 Jun 2023 02:56:17 +0000 (19:56 -0700)
committerGuy Harris <[email protected]>
Wed, 7 Jun 2023 02:56:17 +0000 (19:56 -0700)
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.

tcpdump.c

index b0d3aa5bd6deb1de1edf579b8fbb4f5ac6494ada..8b00cdd17d463540351f4f24654064e61bd1644d 100644 (file)
--- 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)