]> The Tcpdump Group git mirrors - tcpdump/blobdiff - util-print.c
CI: Add warning exemptions for Sun C (suncc-5.14) on Solaris 10
[tcpdump] / util-print.c
index 3b633cd46faa42f99bf44cc30484891468ccb900..594327012e8626e7b3cb04f77fdd3120be468308 100644 (file)
@@ -41,9 +41,6 @@
 
 #include <sys/stat.h>
 
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>
@@ -219,10 +216,14 @@ ts_frac_print(netdissect_options *ndo, const struct timeval *tv)
 
        case PCAP_TSTAMP_PRECISION_MICRO:
                ND_PRINT(".%06u", (unsigned)tv->tv_usec);
+               if ((unsigned)tv->tv_usec > ND_MICRO_PER_SEC - 1)
+                       ND_PRINT(" " ND_INVALID_MICRO_SEC_STR);
                break;
 
        case PCAP_TSTAMP_PRECISION_NANO:
                ND_PRINT(".%09u", (unsigned)tv->tv_usec);
+               if ((unsigned)tv->tv_usec > ND_NANO_PER_SEC - 1)
+                       ND_PRINT(" " ND_INVALID_NANO_SEC_STR);
                break;
 
        default:
@@ -231,6 +232,8 @@ ts_frac_print(netdissect_options *ndo, const struct timeval *tv)
        }
 #else
        ND_PRINT(".%06u", (unsigned)tv->tv_usec);
+       if ((unsigned)tv->tv_usec > ND_MICRO_PER_SEC - 1)
+               ND_PRINT(" " ND_INVALID_MICRO_SEC_STR);
 #endif
 }
 
@@ -246,16 +249,32 @@ ts_date_hmsfrac_print(netdissect_options *ndo, const struct timeval *tv,
        struct tm *tm;
        char timebuf[32];
        const char *timestr;
+#ifdef _WIN32
+       time_t sec;
+#endif
 
        if (tv->tv_sec < 0) {
-               ND_PRINT("[timestamp < 1970-01-01 00:00:00 UTC]");
+               ND_PRINT("[timestamp overflow]");
                return;
        }
 
+#ifdef _WIN32
+       /* on Windows tv->tv_sec is a long not a 64-bit time_t. */
+       sec = tv->tv_sec;
+#endif
+
        if (time_flag == LOCAL_TIME)
+#ifdef _WIN32
+               tm = localtime(&sec);
+#else
                tm = localtime(&tv->tv_sec);
+#endif
        else
+#ifdef _WIN32
+               tm = gmtime(&sec);
+#else
                tm = gmtime(&tv->tv_sec);
+#endif
 
        if (date_flag == WITH_DATE) {
                timestr = nd_format_time(timebuf, sizeof(timebuf),
@@ -276,11 +295,11 @@ static void
 ts_unix_print(netdissect_options *ndo, const struct timeval *tv)
 {
        if (tv->tv_sec < 0) {
-               ND_PRINT("[timestamp < 1970-01-01 00:00:00 UTC]");
+               ND_PRINT("[timestamp overflow]");
                return;
        }
 
-       ND_PRINT("%u", (unsigned)tv->tv_sec);
+       ND_PRINT("%" PRId64, (int64_t)tv->tv_sec);
        ts_frac_print(ndo, tv);
 }
 
@@ -462,6 +481,23 @@ void nd_print_invalid(netdissect_options *ndo)
        ND_PRINT(" (invalid)");
 }
 
+/*
+ * Print a sequence of bytes, separated by a single space.
+ * Stop if truncated (via GET_U_1/longjmp) or after n bytes,
+ * whichever is first.
+ */
+void
+nd_print_bytes_hex(netdissect_options *ndo, const u_char *cp, u_int n)
+{
+       while (n > 0) {
+               ND_PRINT("%02x", GET_U_1(cp));
+               n--;
+               cp++;
+               if (n > 0)
+                       ND_PRINT(" ");
+       }
+}
+
 /*
  *  this is a generic routine for printing unknown data;
  *  we pass on the linefeed plus indentation string to