X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/316dced5e89990e9b37e0ddab466dfbd8ae6dba1..e76768c97a70934b8f3a41fe2df705c61a924a47:/tcpdump.c diff --git a/tcpdump.c b/tcpdump.c index 8407e034..d9f3e0fa 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -650,8 +650,9 @@ show_devices_and_exit (void) */ #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 @@ -665,6 +666,7 @@ static struct option longopts[] = { { "time-stamp-type", required_argument, NULL, 'j' }, { "list-time-stamp-types", no_argument, NULL, 'J' }, #endif + { "time-stamp-precision", required_argument, NULL, OPTION_TSTAMP_PRECISION}, { "dont-verify-checksums", no_argument, NULL, 'K' }, { "list-data-link-types", no_argument, NULL, 'L' }, { "no-optimize", no_argument, NULL, 'O' }, @@ -846,6 +848,18 @@ get_next_file(FILE *VFile, char *ptr) return ret; } +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; +} + int main(int argc, char **argv) { @@ -1281,6 +1295,12 @@ main(int argc, char **argv) exit(0); break; + 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; + default: print_usage(); exit(1); @@ -1372,7 +1392,11 @@ main(int argc, char **argv) RFileName = VFileLine; } - pd = pcap_open_offline(RFileName, ebuf); + if (gndo->ndo_tstamp_precision == PCAP_TSTAMP_PRECISION_NANO) + pd = pcap_open_offline_with_tstamp_precision(RFileName, PCAP_TSTAMP_PRECISION_NANO, ebuf); + else + pd = pcap_open_offline_with_tstamp_precision(RFileName, PCAP_TSTAMP_PRECISION_MICRO, ebuf); + if (pd == NULL) error("%s", ebuf); dlt = pcap_datalink(pd); @@ -1419,6 +1443,13 @@ main(int argc, char **argv) if (Jflag) show_tstamp_types_and_exit(device, pd); #endif + if (gndo->ndo_tstamp_precision == PCAP_TSTAMP_PRECISION_NANO) { + status = pcap_set_tstamp_precision(pd, PCAP_TSTAMP_PRECISION_NANO); + if (status != 0) + error("%s: Can't set nanosecond time stamp precision: %s", + device, pcap_statustostr(status)); + } + /* * Is this an interface that supports monitor mode? */