X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/e1e0824e40f4bfaaec7636f1e452911a6b8f7eca..817ec9f27e76dfe679d40ea4712bfb12ce6e4adf:/tcpdump.c?ds=inline diff --git a/tcpdump.c b/tcpdump.c index 2e9a5055..7db319aa 100644 --- 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' }, @@ -711,7 +715,10 @@ droproot(const char *username, const char *chroot_dir) #ifdef HAVE_CAP_NG_H int ret = capng_change_id(pw->pw_uid, pw->pw_gid, CAPNG_NO_FLAG); if (ret < 0) { - printf("error : ret %d\n", ret); + 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); @@ -730,6 +737,9 @@ droproot(const char *username, const char *chroot_dir) pcap_strerror(errno)); exit(1); } + else { + printf("dropped privs to %s\n", username); + } #endif /* HAVE_CAP_NG_H */ } else { @@ -840,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) { @@ -1275,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); @@ -1366,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); @@ -1413,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? */ @@ -2257,6 +2320,7 @@ static void verbose_stats_dump(int sig _U_) } #endif +USES_APPLE_DEPRECATED_API static void print_version(void) { @@ -2294,6 +2358,7 @@ print_version(void) (void)fprintf (stderr, "SMI-library: %s\n", smi_version_string); #endif } +USES_APPLE_RST static void print_usage(void) @@ -2310,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,