]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add shortcuts for setting time stamp precision 743/head
authorRicardo Nabinger Sanchez <[email protected]>
Tue, 2 Apr 2019 17:28:17 +0000 (14:28 -0300)
committerRicardo Nabinger Sanchez <[email protected]>
Wed, 3 Apr 2019 11:34:41 +0000 (08:34 -0300)
Add two shortcuts (as long-options) for setting the time stamp
precision: --micro and --nano.  While adding these options, reshuffle
the usage message to group up the options related to time stamp, and
removing the macro TIME_STAMP_PRECISION_USAGE.

If setting the time stamp precision is not supported by the available
libpcap, the usage won't mention these options (including
--time-stamp-precision), but they will still be presented in the
manpage.

tcpdump.1.in
tcpdump.c

index 984c19645707eeaa2354fb442810d56aa4420bad..0d4085495f574874f86fbec25a68384c42e6df05 100644 (file)
@@ -478,6 +478,19 @@ The supported values for \fItimestamp_precision\fP are \fBmicro\fP for
 microsecond resolution and \fBnano\fP for nanosecond resolution.  The
 default is microsecond resolution.
 .TP
+.B \-\-micro
+.PD 0
+.TP
+.B \-\-nano
+.PD
+Shorthands for \fB\-\-time\-stamp\-precision=micro\fP or
+\fB\-\-time\-stamp\-precision=nano\fP, adjusting the time stamp
+precision accordingly.  When reading packets from a savefile, using
+\fB\-\-micro\fP truncates time stamps if the savefile was created with
+nanosecond precision.  In contrast, a savefile created with microsecond
+precision will have trailing zeroes added to the time stamp when
+\fB\-\-nano\fP is used.
+.TP
 .B \-K
 .PD 0
 .TP
index 9790a4e3f7c057c2f6bcca927662c79c38a2349b..c4b2c9c4e247c2b0c16988437da43f4afa4ffc60 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -670,6 +670,8 @@ show_remote_devices_and_exit(void)
 #define OPTION_IMMEDIATE_MODE          130
 #define OPTION_PRINT                   131
 #define OPTION_LIST_REMOTE_INTERFACES  132
+#define OPTION_TSTAMP_MICRO            133
+#define OPTION_TSTAMP_NANO             134
 
 static const struct option longopts[] = {
 #if defined(HAVE_PCAP_CREATE) || defined(_WIN32)
@@ -689,6 +691,8 @@ static const struct option longopts[] = {
        { "list-time-stamp-types", no_argument, NULL, 'J' },
 #endif
 #ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
+       { "micro", no_argument, NULL, OPTION_TSTAMP_MICRO},
+       { "nano", no_argument, NULL, OPTION_TSTAMP_NANO},
        { "time-stamp-precision", required_argument, NULL, OPTION_TSTAMP_PRECISION},
 #endif
        { "dont-verify-checksums", no_argument, NULL, 'K' },
@@ -729,12 +733,6 @@ static const struct option longopts[] = {
 #define IMMEDIATE_MODE_USAGE ""
 #endif
 
-#ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
-#define TIME_STAMP_PRECISION_USAGE " [ --time-stamp-precision precision ]"
-#else
-#define TIME_STAMP_PRECISION_USAGE
-#endif
-
 #ifndef _WIN32
 /* Drop root privileges and chroot if necessary */
 static void
@@ -1860,6 +1858,16 @@ main(int argc, char **argv)
                        print = 1;
                        break;
 
+#ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
+               case OPTION_TSTAMP_MICRO:
+                       ndo->ndo_tstamp_precision = PCAP_TSTAMP_PRECISION_MICRO;
+                       break;
+
+               case OPTION_TSTAMP_NANO:
+                       ndo->ndo_tstamp_precision = PCAP_TSTAMP_PRECISION_NANO;
+                       break;
+#endif
+
                default:
                        print_usage();
                        exit_tcpdump(S_ERR_HOST_PROGRAM);
@@ -3074,11 +3082,13 @@ print_usage(void)
        (void)fprintf(stderr,
 "\t\t[ -M secret ] [ --number ] [ --print ]" Q_FLAG_USAGE "\n");
        (void)fprintf(stderr,
-"\t\t[ -r file ] [ -s snaplen ]" TIME_STAMP_PRECISION_USAGE "\n");
+"\t\t[ -r file ] [ -s snaplen ] [ -T type ] [ --version ]\n");
        (void)fprintf(stderr,
-"\t\t[ -T type ] [ --version ] [ -V file ] [ -w file ]\n");
+"\t\t[ -V file ] [ -w file ] [ -W filecount ] [ -y datalinktype ]\n");
+#ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
        (void)fprintf(stderr,
-"\t\t[ -W filecount ] [ -y datalinktype ]\n");
+"\t\t[ --time-stamp-precision precision ] [ --micro ] [ --nano ]\n");
+#endif
        (void)fprintf(stderr,
 "\t\t[ -z postrotate-command ] [ -Z user ] [ expression ]\n");
 }