summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2014-06-25 12:06:35 -0700
committerGuy Harris <guy@alum.mit.edu>2014-06-25 12:06:35 -0700
commita509c52d31d1835d54295e9157d9ec387b27520b (patch)
treec408c48a9eadc7311d28a49023d21bcdca5bad62
parente76768c97a70934b8f3a41fe2df705c61a924a47 (diff)
downloadtcpdump-a509c52d31d1835d54295e9157d9ec387b27520b.tar.gz
Allow builds if libpcap doesn't have pcap_set_tstamp_precision().
Check for pcap_set_tstamp_precision() in the configure script and, if it's not there, don't include the code that allows time stamp precisions to be set.
-rw-r--r--config.h.in3
-rwxr-xr-xconfigure15
-rw-r--r--configure.in5
-rw-r--r--tcpdump.c60
-rw-r--r--util.c22
5 files changed, 89 insertions, 16 deletions
diff --git a/config.h.in b/config.h.in
index d7f37c6a..eb48e224 100644
--- a/config.h.in
+++ b/config.h.in
@@ -121,6 +121,9 @@
/* Define to 1 if you have the `pcap_set_datalink' function. */
#undef HAVE_PCAP_SET_DATALINK
+/* Define to 1 if you have the `pcap_set_tstamp_precision' function. */
+#undef HAVE_PCAP_SET_TSTAMP_PRECISION
+
/* Define to 1 if you have the `pcap_set_tstamp_type' function. */
#undef HAVE_PCAP_SET_TSTAMP_TYPE
diff --git a/configure b/configure
index c8f9590c..08c2a6af 100755
--- a/configure
+++ b/configure
@@ -6580,6 +6580,21 @@ _ACEOF
fi
done
+ #
+ # And do we have pcap_set_tstamp_precision? If so, we assume
+ # we also have pcap_open_offline_with_tstamp_precision.
+ #
+ for ac_func in pcap_set_tstamp_precision
+do :
+ ac_fn_c_check_func "$LINENO" "pcap_set_tstamp_precision" "ac_cv_func_pcap_set_tstamp_precision"
+if test "x$ac_cv_func_pcap_set_tstamp_precision" = xyes; then :
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_PCAP_SET_TSTAMP_PRECISION 1
+_ACEOF
+
+fi
+done
+
fi
for ac_func in pcap_findalldevs pcap_dump_flush pcap_lib_version pcap_setdirection
diff --git a/configure.in b/configure.in
index d9f2b59a..c88f4705 100644
--- a/configure.in
+++ b/configure.in
@@ -720,6 +720,11 @@ if test $ac_cv_func_pcap_create = "yes" ; then
# pcap_list_tstamp_types and pcap_free_tstamp_types as well.
#
AC_CHECK_FUNCS(pcap_set_tstamp_type)
+ #
+ # And do we have pcap_set_tstamp_precision? If so, we assume
+ # we also have pcap_open_offline_with_tstamp_precision.
+ #
+ AC_CHECK_FUNCS(pcap_set_tstamp_precision)
fi
AC_CHECK_FUNCS(pcap_findalldevs pcap_dump_flush pcap_lib_version pcap_setdirection)
diff --git a/tcpdump.c b/tcpdump.c
index d9f3e0fa..7db319aa 100644
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -648,9 +648,9 @@ 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_TSTAMP_PRECISION 130
+#define OPTION_NUMBER 128
+#define OPTION_VERSION 129
+#define OPTION_TSTAMP_PRECISION 130
static const struct option longopts[] = {
#if defined(HAVE_PCAP_CREATE) || defined(WIN32)
@@ -666,7 +666,9 @@ static const struct option longopts[] = {
{ "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' },
{ "no-optimize", no_argument, NULL, 'O' },
@@ -848,6 +850,7 @@ get_next_file(FILE *VFile, char *ptr)
return ret;
}
+#ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
static int
tstamp_precision_from_string(const char *precision)
{
@@ -860,6 +863,23 @@ tstamp_precision_from_string(const char *precision)
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)
{
@@ -1295,11 +1315,13 @@ 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();
@@ -1392,10 +1414,12 @@ main(int argc, char **argv)
RFileName = VFileLine;
}
- 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);
+#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);
@@ -1443,12 +1467,14 @@ 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));
- }
+#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?
@@ -2349,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,
diff --git a/util.c b/util.c
index ef9ed7be..5731ca7b 100644
--- a/util.c
+++ b/util.c
@@ -138,8 +138,26 @@ static char *
ts_format(netdissect_options *ndo, int sec, int usec)
{
static char buf[sizeof("00:00:00.000000000")];
- const char *format = ndo->ndo_tstamp_precision == PCAP_TSTAMP_PRECISION_NANO ?
- "%02d:%02d:%02d.%09u" : "%02d:%02d:%02d.%06u";
+ const char *format;
+
+#ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
+ switch (ndo->ndo_tstamp_precision) {
+
+ case PCAP_TSTAMP_PRECISION_MICRO:
+ format = "%02d:%02d:%02d.%06u";
+ break;
+
+ case PCAP_TSTAMP_PRECISION_NANO:
+ format = "%02d:%02d:%02d.%09u";
+ break;
+
+ default:
+ format = "%02d:%02d:%02d.{unknown precision}";
+ break;
+ }
+#else
+ format = "%02d:%02d:%02d.%06u";
+#endif
snprintf(buf, sizeof(buf), format,
sec / 3600, (sec % 3600) / 60, sec % 60, usec);