X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/21cf6d8a4e3c82d83eef820801e69b0328acc431..c602726f3a91f2c344bde10c6e2f3c6149a15adc:/tcpdump.c diff --git a/tcpdump.c b/tcpdump.c index 5f9a34bf..d5766712 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -203,7 +203,9 @@ static int Qflag = -1; /* restrict captured packet by send/receive direction * static int Uflag; /* "unbuffered" output of dump files */ 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; @@ -730,7 +732,7 @@ droproot(const char *username, const char *chroot_dir) { int ret = capng_change_id(pw->pw_uid, pw->pw_gid, CAPNG_NO_FLAG); if (ret < 0) - error("capng_change_id(): return %d\n", ret); + error("capng_change_id(): return %d", ret); else fprintf(stderr, "dropped privs to %s\n", username); } @@ -1372,7 +1374,7 @@ open_interface(const char *device, netdissect_options *ndo, char *ebuf) * specific case would be an error message that looks a bit odd. */ newdev[strlen(newdev)-1]++; - error("%s is not a monitor mode VAP\n" + error("%s is not a monitor mode VAP" "To create a new monitor mode VAP use:\n" " ifconfig %s create wlandev %s wlanmode monitor\n" "and use %s as the tcpdump interface", @@ -2014,7 +2016,11 @@ main(int argc, char **argv) break; #endif case 'z': +#if defined(HAVE_FORK) || defined(HAVE_VFORK) zflag = optarg; +#else + error("-z cannot be used. Fork subprocess not implemented."); +#endif break; case 'Z': @@ -2100,11 +2106,19 @@ main(int argc, char **argv) } if (ndo->ndo_Aflag && ndo->ndo_xflag) - warning("-A and -x[x] are mutually exclusive. -A ignored."); + error("-A and -x[x] are mutually exclusive."); if (ndo->ndo_Aflag && ndo->ndo_Xflag) - warning("-A and -X[X] are mutually exclusive. -A ignored."); + error("-A and -X[X] are mutually exclusive."); if (ndo->ndo_xflag && ndo->ndo_Xflag) - warning("-x[x] and -X[X] are mutually exclusive. -x[x] ignored."); + error("-x[x] and -X[X] are mutually exclusive."); + if (Cflag != 0 && WFileName == NULL) + error("-C cannot be used without -w."); + if (Gflag != 0 && WFileName == NULL) + error("-G cannot be used without -w."); +#if defined(HAVE_FORK) || defined(HAVE_VFORK) + if (zflag != NULL && (WFileName == NULL || (Cflag == 0 && Gflag == 0))) + error("-z cannot be used without -w and (-C or -G)."); +#endif if (cnt != -1) if ((int)packets_to_skip > (INT_MAX - cnt)) @@ -2135,7 +2149,7 @@ main(int argc, char **argv) } if (ndo->ndo_fflag != 0 && (VFileName != NULL || RFileName != NULL)) - error("-f can not be used with -V or -r"); + error("-f cannot be used with -V or -r."); if (VFileName != NULL && RFileName != NULL) error("-V and -r are mutually exclusive."); @@ -2203,11 +2217,11 @@ main(int argc, char **argv) VFile = fopen(VFileName, "r"); if (VFile == NULL) - error("Unable to open file: %s\n", pcap_strerror(errno)); + error("Unable to open file: %s", pcap_strerror(errno)); ret = get_next_file(VFile, VFileLine); if (!ret) - error("Nothing in %s\n", VFileName); + error("Nothing in %s", VFileName); RFileName = VFileLine; } @@ -3134,15 +3148,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 close_old_dump_file(struct dump_info *dump_info) @@ -3152,11 +3158,13 @@ close_old_dump_file(struct dump_info *dump_info) */ 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 } static void