]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Better report errors from stub routines in macOS 14 (Sonoma) libpcap.
authorGuy Harris <[email protected]>
Sat, 23 Sep 2023 20:06:27 +0000 (13:06 -0700)
committerGuy Harris <[email protected]>
Sat, 23 Sep 2023 20:06:27 +0000 (13:06 -0700)
Some routines that are built only if libpcap 1.10.x is built with remote
capture support, but that are unconditionally declared in pcap/pcap.h,
now have stub implementations in macOS 14 that always fail and set the
error string to "not supported".  (This was probably done because those
routines are now declared as "weakly linked symbols":

https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html

om macOS 14.)

This means CMakeLists.txt finds them when you build on Sonoma, so we end
up calling them.

For all code that calls the routines in question, if the any of the
routines in question fail, check for an error string of "not supported",
and report that error as it with "Remote capture not supported", so as
to make the cause of failure clearer.

Fix the misindentation of a closing bracket while we're at it.

tcpdump.c

index 3474396646c056e786b4a355a46077749e2431f7..7731ea0e39a05d4d67b77b348c0278f9569ac48d 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -563,8 +563,21 @@ show_remote_devices_and_exit(void)
        int i;
 
        if (pcap_findalldevs_ex(remote_interfaces_source, NULL, &devlist,
-           ebuf) < 0)
+           ebuf) < 0) {
+               if (strcmp(ebuf, "not supported") == 0) {
+                       /*
+                        * macOS 14's pcap_findalldevs_ex(), which is a
+                        * stub that always returns -1 with an error
+                        * message of "not supported".
+                        *
+                        * In this case, as we passed it an rpcap://
+                        * URL, treat that as meaning "remote capture
+                        * not supported".
+                        */
+                       error("Remote capture not supported");
+               }
                error("%s", ebuf);
+       }
        for (i = 0, dev = devlist; dev != NULL; i++, dev = dev->next) {
                printf("%d.%s", i+1, dev->name);
                if (dev->description != NULL)
@@ -1269,6 +1282,18 @@ open_interface(const char *device, netdissect_options *ndo, char *ebuf)
                    pflag ? 0 : PCAP_OPENFLAG_PROMISCUOUS, timeout, NULL,
                    ebuf);
                if (pc == NULL) {
+                       /*
+                        * macOS 14's pcap_pcap_open(), which is a
+                        * stub that always returns NULL with an error
+                        * message of "not supported".
+                        *
+                        * In this case, as we passed it an rpcap://
+                        * URL, treat that as meaning "remote capture
+                        * not supported".
+                        */
+                       if (strcmp(ebuf, "not supported") == 0)
+                               error("Remote capture not supported");
+
                        /*
                         * If this failed with "No such device" or "The system
                         * cannot find the device specified", that means
@@ -1438,7 +1463,7 @@ open_interface(const char *device, netdissect_options *ndo, char *ebuf)
                if (status != 0)
                        error("%s: pcap_setdirection() failed: %s",
                              device,  pcap_geterr(pc));
-               }
+       }
 #endif /* HAVE_PCAP_SETDIRECTION */
 #else /* HAVE_PCAP_CREATE */
        *ebuf = '\0';