]> The Tcpdump Group git mirrors - tcpdump/blobdiff - tcpdump.c
Shorten a status text description.
[tcpdump] / tcpdump.c
index fc15b42367fa280f5d687832094dedf5f967b378..7db319aa43d6006ebde49c242141de6a7fe86eb8 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -648,10 +648,11 @@ show_devices_and_exit (void)
  * component of the entry for the long option, and have a case for that
  * option in the switch statement.
  */
-#define OPTION_NUMBER  128
-#define OPTION_VERSION 129
+#define OPTION_NUMBER          128
+#define OPTION_VERSION         129
+#define OPTION_TSTAMP_PRECISION        130
 
-static struct option longopts[] = {
+static const struct option longopts[] = {
 #if defined(HAVE_PCAP_CREATE) || defined(WIN32)
        { "buffer-size", required_argument, NULL, 'B' },
 #endif
@@ -664,6 +665,9 @@ static struct option longopts[] = {
 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
        { "time-stamp-type", required_argument, NULL, 'j' },
        { "list-time-stamp-types", no_argument, NULL, 'J' },
+#endif
+#ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
+       { "time-stamp-precision", required_argument, NULL, OPTION_TSTAMP_PRECISION},
 #endif
        { "dont-verify-checksums", no_argument, NULL, 'K' },
        { "list-data-link-types", no_argument, NULL, 'L' },
@@ -713,6 +717,9 @@ droproot(const char *username, const char *chroot_dir)
                if (ret < 0) {
                        fprintf(stderr, "error : ret %d\n", ret);
                }
+               else {
+                       printf("dropped privs to %s\n", username);
+               }
                /* We don't need CAP_SETUID and CAP_SETGID */
                capng_update(CAPNG_DROP, CAPNG_EFFECTIVE, CAP_SETUID);
                capng_update(CAPNG_DROP, CAPNG_EFFECTIVE, CAP_SETUID);
@@ -843,6 +850,36 @@ get_next_file(FILE *VFile, char *ptr)
        return ret;
 }
 
+#ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
+static int
+tstamp_precision_from_string(const char *precision)
+{
+       if (strncmp(precision, "nano", strlen("nano")) == 0)
+               return PCAP_TSTAMP_PRECISION_NANO;
+
+       if (strncmp(precision, "micro", strlen("micro")) == 0)
+               return PCAP_TSTAMP_PRECISION_MICRO;
+
+       return -EINVAL;
+}
+
+static const char *
+tstamp_precision_to_string(int precision)
+{
+       switch (precision) {
+
+       case PCAP_TSTAMP_PRECISION_MICRO:
+               return "micro";
+
+       case PCAP_TSTAMP_PRECISION_NANO:
+               return "nano";
+
+       default:
+               return "unknown";
+       }
+}
+#endif
+
 int
 main(int argc, char **argv)
 {
@@ -1278,6 +1315,14 @@ main(int argc, char **argv)
                        exit(0);
                        break;
 
+#ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
+               case OPTION_TSTAMP_PRECISION:
+                       gndo->ndo_tstamp_precision = tstamp_precision_from_string(optarg);
+                       if (gndo->ndo_tstamp_precision < 0)
+                               error("unsupported time stamp precision");
+                       break;
+#endif
+
                default:
                        print_usage();
                        exit(1);
@@ -1369,7 +1414,13 @@ main(int argc, char **argv)
                        RFileName = VFileLine;
                }
 
+#ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
+               pd = pcap_open_offline_with_tstamp_precision(RFileName,
+                   gndo->ndo_tstamp_precision, ebuf);
+#else
                pd = pcap_open_offline(RFileName, ebuf);
+#endif
+
                if (pd == NULL)
                        error("%s", ebuf);
                dlt = pcap_datalink(pd);
@@ -1416,6 +1467,15 @@ main(int argc, char **argv)
                if (Jflag)
                        show_tstamp_types_and_exit(device, pd);
 #endif
+#ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
+               status = pcap_set_tstamp_precision(pd, gndo->ndo_tstamp_precision);
+               if (status != 0)
+                       error("%s: Can't set %ssecond time stamp precision: %s",
+                               device,
+                               tstamp_precision_to_string(gndo->ndo_tstamp_precision),
+                               pcap_statustostr(status));
+#endif
+
                /*
                 * Is this an interface that supports monitor mode?
                 */
@@ -2315,7 +2375,13 @@ print_usage(void)
 "\t\t[ -Q in|out|inout ]\n");
 #endif
        (void)fprintf(stderr,
-"\t\t[ -r file ] [ -s snaplen ] [ -T type ] [ --version ] [ -V file ]\n");
+"\t\t[ -r file ] [ -s snaplen ] ");
+#ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
+       (void)fprintf(stderr, "[ --time-stamp-precision precision ]\n");
+       (void)fprintf(stderr,
+"\t\t");
+#endif
+       (void)fprintf(stderr, "[ -T type ] [ --version ] [ -V file ]\n");
        (void)fprintf(stderr,
 "\t\t[ -w file ] [ -W filecount ] [ -y datalinktype ] [ -z command ]\n");
        (void)fprintf(stderr,