]> The Tcpdump Group git mirrors - tcpdump/blobdiff - tcpdump.c
CI: Add warning exemptions for Sun C (suncc-5.14) on Solaris 10
[tcpdump] / tcpdump.c
index ed4b778fd02de0418a8e388f94d69dcdf135ad8e..e59756716de5438422efb332861807e4ed647f06 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -140,7 +140,6 @@ The Regents of the University of California.  All rights reserved.\n";
 #include <sys/sysctl.h>
 #endif /* __FreeBSD__ */
 
-#include "netdissect-stdinc.h"
 #include "netdissect.h"
 #include "interface.h"
 #include "addrtoname.h"
@@ -617,7 +616,27 @@ show_remote_devices_and_exit(void)
 #define m_FLAG_USAGE "[ -m module ] ..."
 #endif
 
-#define SHORTOPTS "aAbB:c:C:dDeE:fF:G:hHi:I" j_FLAG J_FLAG "KlLm:M:nNOpqQ:r:s:StT:uUvV:w:W:xXy:Yz:Z:#"
+#if defined(HAVE_FORK) || defined(HAVE_VFORK)
+#define z_FLAG         "z:"
+#define z_FLAG_USAGE    "[ -z postrotate-command ] "
+#else
+#define z_FLAG
+#define z_FLAG_USAGE
+#endif
+
+#ifdef HAVE_LIBCRYPTO
+#define E_FLAG         "E:"
+#define E_FLAG_USAGE    "[ -E algo:secret ] "
+#define M_FLAG         "M:"
+#define M_FLAG_USAGE   "[ -M secret ] "
+#else
+#define E_FLAG
+#define E_FLAG_USAGE
+#define M_FLAG
+#define M_FLAG_USAGE
+#endif
+
+#define SHORTOPTS "aAbB:c:C:dDe" E_FLAG "fF:G:hHi:I" j_FLAG J_FLAG "KlLm:" M_FLAG "nNOpqQ:r:s:StT:uUvV:w:W:xXy:Y" z_FLAG "Z:#"
 
 /*
  * Long options.
@@ -732,7 +751,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);
                }
@@ -1374,7 +1393,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",
@@ -1768,12 +1787,11 @@ main(int argc, char **argv)
                        ++ndo->ndo_eflag;
                        break;
 
+#ifdef HAVE_LIBCRYPTO
                case 'E':
-#ifndef HAVE_LIBCRYPTO
-                       warning("crypto code not compiled in");
-#endif
                        ndo->ndo_espsecret = optarg;
                        break;
+#endif
 
                case 'f':
                        ++ndo->ndo_fflag;
@@ -1859,13 +1877,12 @@ main(int argc, char **argv)
                        }
                        break;
 
+#ifdef HAVE_LIBCRYPTO
                case 'M':
                        /* TCP-MD5 shared secret */
-#ifndef HAVE_LIBCRYPTO
-                       warning("crypto code not compiled in");
-#endif
                        ndo->ndo_sigsecret = optarg;
                        break;
+#endif
 
                case 'n':
                        ++ndo->ndo_nflag;
@@ -2015,13 +2032,12 @@ main(int argc, char **argv)
                        }
                        break;
 #endif
-               case 'z':
+
 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
+               case 'z':
                        zflag = optarg;
-#else
-                       warning("-z ignored. Fork subprocess not implemented.\n");
-#endif
                        break;
+#endif
 
                case 'Z':
                        username = optarg;
@@ -2106,11 +2122,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))
@@ -2141,7 +2165,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.");
@@ -2209,11 +2233,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;
                }
 
@@ -3455,7 +3479,7 @@ print_usage(FILE *f)
        (void)fprintf(f,
 "Usage: %s [-AbdDefhHI" J_FLAG "KlLnNOpqStuUvxX#] [ -B size ] [ -c count ] [--count]\n", program_name);
        (void)fprintf(f,
-"\t\t[ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]\n");
+"\t\t[ -C file_size ] " E_FLAG_USAGE "[ -F file ] [ -G seconds ]\n");
        (void)fprintf(f,
 "\t\t[ -i interface ]" IMMEDIATE_MODE_USAGE j_FLAG_USAGE "\n");
        (void)fprintf(f,
@@ -3465,7 +3489,7 @@ print_usage(FILE *f)
 "\t\t" m_FLAG_USAGE "\n");
 #endif
        (void)fprintf(f,
-"\t\t[ -M secret ] [ --number ] [ --print ]\n");
+"\t\t" M_FLAG_USAGE "[ --number ] [ --print ]\n");
        (void)fprintf(f,
 "\t\t[ --print-sampling nth ] [ -Q in|out|inout ] [ -r file ]\n");
        (void)fprintf(f,
@@ -3477,5 +3501,5 @@ print_usage(FILE *f)
 "\t\t[ --time-stamp-precision precision ] [ --micro ] [ --nano ]\n");
 #endif
        (void)fprintf(f,
-"\t\t[ -z postrotate-command ] [ -Z user ] [ expression ]\n");
+"\t\t" z_FLAG_USAGE "[ -Z user ] [ expression ]\n");
 }