]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Update the -z option processing
authorFrancois-Xavier Le Bail <[email protected]>
Sat, 5 Apr 2025 14:52:08 +0000 (16:52 +0200)
committerfxlb <[email protected]>
Sun, 6 Apr 2025 05:08:07 +0000 (05:08 +0000)
It can only be used if defined(HAVE_FORK) || defined(HAVE_VFORK).

This avoid:
tcpdump.c:3140:31: warning: unused parameter 'filename'
  [-Wunused-parameter] compress_savefile(const char *filename)

(backported from commit 8fac227c17aa5f1c09f35626738cd68de03843b8)

tcpdump.c

index 3905020093648ace467933461e081cc6bcbd25d3..8b155ab293dc3129e8f9e4cbdf3766d84d5b2b05 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -226,7 +226,9 @@ static int Uflag;                   /* "unbuffered" output of dump files */
 #endif
 static int Wflag;                      /* recycle output files after this number of files */
 static int WflagChars;
+#if defined(HAVE_FORK) || defined(HAVE_VFORK)
 static char *zflag = NULL;             /* compress each savefile using a specified command (like gzip or bzip2) */
+#endif
 static int timeout = 1000;             /* default timeout = 1000 ms = 1 s */
 #ifdef HAVE_PCAP_SET_IMMEDIATE_MODE
 static int immediate_mode;
@@ -2122,7 +2124,11 @@ main(int argc, char **argv)
                        break;
 #endif
                case 'z':
+#if defined(HAVE_FORK) || defined(HAVE_VFORK)
                        zflag = optarg;
+#else
+                       warning("-z ignored. Fork subprocess not implemented.\n");
+#endif
                        break;
 
                case 'Z':
@@ -3141,15 +3147,7 @@ compress_savefile(const char *filename)
        _exit(S_ERR_HOST_PROGRAM);
 #endif
 }
-#else  /* HAVE_FORK && HAVE_VFORK */
-static void
-compress_savefile(const char *filename)
-{
-       fprintf(stderr,
-               "%s failed. Functionality not implemented under your system\n",
-               __func__);
-}
-#endif /* HAVE_FORK && HAVE_VFORK */
+#endif /* HAVE_FORK || HAVE_VFORK */
 
 static void
 dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
@@ -3197,11 +3195,13 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s
                         */
                        pcap_dump_close(dump_info->pdd);
 
+#if defined(HAVE_FORK) || defined(HAVE_VFORK)
                        /*
                         * Compress the file we just closed, if the user asked for it
                         */
                        if (zflag != NULL)
                                compress_savefile(dump_info->CurrentFileName);
+#endif
 
                        /*
                         * Check to see if we've exceeded the Wflag (when
@@ -3302,12 +3302,14 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s
                         */
                        pcap_dump_close(dump_info->pdd);
 
+#if defined(HAVE_FORK) || defined(HAVE_VFORK)
                        /*
                         * Compress the file we just closed, if the user
                         * asked for it.
                         */
                        if (zflag != NULL)
                                compress_savefile(dump_info->CurrentFileName);
+#endif
 
                        Cflag_count++;
                        if (Wflag > 0) {