]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Don't try to print deltas from zero.
authorfenner <fenner>
Fri, 1 Aug 2003 01:18:24 +0000 (01:18 +0000)
committerfenner <fenner>
Fri, 1 Aug 2003 01:18:24 +0000 (01:18 +0000)
Print the value of the times if strftime is available.

Submitted by: Keith Reynolds
Sourceforge Tracker #734407

configure.in
print-ntp.c

index 712585e7d162db6db09087976d151d409d93c2e7..0532c1c2736f589452b270f29ec76ad943545c8e 100644 (file)
@@ -1,4 +1,4 @@
-dnl @(#) $Header: /tcpdump/master/tcpdump/configure.in,v 1.168 2003-07-17 13:39:03 itojun Exp $ (LBL)
+dnl @(#) $Header: /tcpdump/master/tcpdump/configure.in,v 1.169 2003-08-01 01:18:24 fenner Exp $ (LBL)
 dnl
 dnl Copyright (c) 1994, 1995, 1996, 1997
 dnl    The Regents of the University of California.  All rights reserved.
@@ -6,7 +6,7 @@ dnl
 dnl Process this file with autoconf to produce a configure script.
 dnl
 
-AC_REVISION($Revision: 1.168 $)
+AC_REVISION($Revision: 1.169 $)
 AC_PREREQ(2.13)
 AC_INIT(tcpdump.c)
 
@@ -480,6 +480,7 @@ fi
 
 
 AC_REPLACE_FUNCS(vfprintf strcasecmp strlcat strlcpy strdup strsep)
+AC_CHECK_FUNCS(strftime)
 AC_CHECK_FUNCS(ether_ntohost, [
     AC_CACHE_CHECK(for buggy ether_ntohost, ac_cv_buggy_ether_ntohost, [
        AC_TRY_RUN([
index 1d32fda80d14340e4e615b1c2a75f7bec14feeff..6be68be1697b2072f7d97c998ee2653dade0cc9a 100644 (file)
@@ -25,7 +25,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ntp.c,v 1.36 2002-12-28 17:15:06 hannes Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ntp.c,v 1.37 2003-08-01 01:18:24 fenner Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -36,6 +36,9 @@ static const char rcsid[] =
 
 #include <stdio.h>
 #include <string.h>
+#ifdef HAVE_STRFTIME
+#include <time.h>
+#endif
 
 #include "interface.h"
 #include "addrtoname.h"
@@ -223,6 +226,21 @@ p_ntp_time(register const struct l_fixedpt *lfp)
        ff = ff / FMAXINT;      /* shift radix point by 32 bits */
        f = ff * 1000000000.0;  /* treat fraction as parts per billion */
        printf("%u.%09d", i, f);
+
+#ifdef HAVE_STRFTIME
+       /*
+        * For extra verbosity, print the time in human-readable format.
+        */
+       if (vflag > 1 && i) {
+           time_t seconds = i - JAN_1970;
+           struct tm *tm;
+           char time_buf[128];
+
+           tm = localtime(&seconds);
+           strftime(time_buf, sizeof (time_buf), "%Y/%m/%d %H:%M:%S", tm);
+           printf (" (%s)", time_buf);
+       }
+#endif
 }
 
 /* Prints time difference between *lfp and *olfp */
@@ -231,16 +249,22 @@ p_ntp_delta(register const struct l_fixedpt *olfp,
            register const struct l_fixedpt *lfp)
 {
        register int32_t i;
-       register u_int32_t uf;
-       register u_int32_t ouf;
+       register u_int32_t u, uf;
+       register u_int32_t ou, ouf;
        register u_int32_t f;
        register float ff;
        int signbit;
 
-       i = EXTRACT_32BITS(&lfp->int_part) - EXTRACT_32BITS(&olfp->int_part);
-
+       u = EXTRACT_32BITS(&lfp->int_part);
+       ou = EXTRACT_32BITS(&olfp->int_part);
        uf = EXTRACT_32BITS(&lfp->fraction);
        ouf = EXTRACT_32BITS(&olfp->fraction);
+       if (ou == 0 && ouf == 0) {
+               p_ntp_time(lfp);
+               return;
+       }
+
+       i = u - ou;
 
        if (i > 0) {            /* new is definitely greater than old */
                signbit = 0;