]> The Tcpdump Group git mirrors - tcpdump/commitdiff
ZEP: use the exissting NTP time formatting code.
authorGuy Harris <[email protected]>
Fri, 29 Mar 2024 05:49:42 +0000 (22:49 -0700)
committerGuy Harris <[email protected]>
Fri, 29 Mar 2024 05:49:42 +0000 (22:49 -0700)
The strftime() format for that case is slightly different, so add a new
p_ntp_time_fmt() routine that takes a strftime() format, and use that in
ZEP.

That way, we can benefit from any handling of times not fitting in a
time_t being done by the NTP time printing code.

ntp.c
ntp.h
print-zep.c

diff --git a/ntp.c b/ntp.c
index 967644e0e1b9c9158ec0a6a5cb082451db42cf2c..6c4b7f32fde787c5e31129d4a43e5722702fc766 100644 (file)
--- a/ntp.c
+++ b/ntp.c
@@ -29,7 +29,7 @@
 #define        JAN_1970        INT64_T_CONSTANT(2208988800)    /* 1970 - 1900 in seconds */
 
 void
-p_ntp_time(netdissect_options *ndo,
+p_ntp_time_fmt(netdissect_options *ndo, const char *fmt,
           const struct l_fixedpt *lfp)
 {
        uint32_t i;
@@ -63,10 +63,16 @@ p_ntp_time(netdissect_options *ndo,
                 */
                time_string = "[Time is too large to fit into a time_t]";
            } else {
-               /* use ISO 8601 (RFC3339) format */
                time_string = nd_format_time(time_buf, sizeof (time_buf),
-                 "%Y-%m-%dT%H:%M:%SZ", gmtime(&seconds));
+                 fmt, gmtime(&seconds));
            }
            ND_PRINT(" (%s)", time_string);
        }
 }
+
+void
+p_ntp_time(netdissect_options *ndo, const struct l_fixedpt *lfp)
+{
+       /* use ISO 8601 (RFC3339) format */
+       p_ntp_time_fmt(ndo, "%Y-%m-%dT%H:%M:%SZ", lfp);
+}
diff --git a/ntp.h b/ntp.h
index 78644e28215625fbdd7b68d75282cc3801ffdba4..0fe4214281a2af09f66779eb4d24b45a0bed78e2 100644 (file)
--- a/ntp.h
+++ b/ntp.h
@@ -51,4 +51,6 @@ struct s_fixedpt {
        nd_uint16_t fraction;
 };
 
+void p_ntp_time_fmt(netdissect_options *, const char *fmt,
+                    const struct l_fixedpt *);
 void p_ntp_time(netdissect_options *, const struct l_fixedpt *);
index c507e369d38b9f7de8a9f6708cc36d8a5fd778d7..20a1e2ae6ddfa50ac08fe7ecd552428250f717e5 100644 (file)
@@ -30,6 +30,8 @@
 
 #include "extract.h"
 
+#include "ntp.h"
+
 /* From wireshark packet-zep.c:
  *
  ***********************************************************************
  *------------------------------------------------------------
  */
 
-#define     JAN_1970        2208988800U
-
-/* Print timestamp */
-static void zep_print_ts(netdissect_options *ndo, const u_char *p)
-{
-       int32_t i;
-       uint32_t uf;
-       uint32_t f;
-       float ff;
-
-       i = GET_BE_U_4(p);
-       uf = GET_BE_U_4(p + 4);
-       ff = (float) uf;
-       if (ff < 0.0)           /* some compilers are buggy */
-               ff += FMAXINT;
-       ff = (float) (ff / FMAXINT); /* shift radix point by 32 bits */
-       f = (uint32_t) (ff * 1000000000.0);  /* treat fraction as parts per
-                                               billion */
-       ND_PRINT("%u.%09d", i, f);
-
-       /*
-        * print the time in human-readable format.
-        */
-       if (i) {
-               time_t seconds = i - JAN_1970;
-               char time_buf[128];
-
-               ND_PRINT(" (%s)",
-                   nd_format_time(time_buf, sizeof (time_buf), "%Y-%m-%d %H:%M:%S",
-                     localtime(&seconds)));
-       }
-}
-
 /*
  * Main function to print packets.
  */
@@ -151,7 +120,12 @@ zep_print(netdissect_options *ndo,
                        else
                                ND_PRINT("LQI %u, ", GET_U_1(bp + 8));
 
-                       zep_print_ts(ndo, bp + 9);
+                       /*
+                        * XXX - why a space rather than a "T"
+                        * between the date and time?
+                        */
+                       p_ntp_time_fmt(ndo, "%Y-%m-%d %H:%M:%S",
+                           (const struct l_fixedpt *)(bp + 9));
                        seq_no = GET_BE_U_4(bp + 17);
                        inner_len = GET_U_1(bp + 31);
                        ND_PRINT(", seq# = %u, inner len = %u",