]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-arista.c
CI: Add warning exemptions for Sun C (suncc-5.15) on Solaris 10
[tcpdump] / print-arista.c
index 444fcca428a14454de96222734a9784a18094625..0ec04889b6a212a5c34af18daace66c935a8d047 100644 (file)
@@ -2,15 +2,13 @@
 
 /* \summary: EtherType protocol for Arista Networks printer */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include "netdissect-stdinc.h"
 
 #include "netdissect.h"
 #include "extract.h"
-#include "addrtoname.h"
+#include "timeval-operations.h"
 
 /*
 
@@ -57,6 +55,9 @@ The two-byte version value is split into 3 fields:
 |   timescale   | format|hw info|
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 
+
+See also: https://www.arista.com/assets/data/pdf/Whitepapers/Overview_Arista_Timestamps.pdf
+
 */
 
 #define ARISTA_SUBTYPE_TIMESTAMP 0x0001
@@ -86,21 +87,17 @@ static const struct tok hw_info_str[] = {
 };
 
 static inline void
-arista_print_date_hms_time(netdissect_options *ndo, uint32_t seconds,
-               uint32_t nanoseconds)
+arista_print_date_hms_time(netdissect_options *ndo, const uint32_t seconds,
+               const uint32_t nanoseconds)
 {
-       time_t ts;
-       struct tm *tm;
-       char buf[BUFSIZE];
-
-       ts = seconds + (nanoseconds / 1000000000);
-       nanoseconds %= 1000000000;
-       if (NULL == (tm = gmtime(&ts)))
-               ND_PRINT("gmtime() error");
-       else if (0 == strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm))
-               ND_PRINT("strftime() error");
-       else
-               ND_PRINT("%s.%09u", buf, nanoseconds);
+       const time_t ts = seconds;
+       char buf[sizeof("-yyyyyyyyyy-mm-dd hh:mm:ss")];
+
+       ND_PRINT("%s.%09u",
+           nd_format_time(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S",
+              gmtime(&ts)), nanoseconds);
+       if (nanoseconds > ND_NANO_PER_SEC - 1)
+               ND_PRINT(" " ND_INVALID_NANO_SEC_STR);
 }
 
 int
@@ -121,7 +118,7 @@ arista_ethertype_print(netdissect_options *ndo, const u_char *bp, u_int len _U_)
 
        // TapAgg Header Timestamping
        if (subTypeId == ARISTA_SUBTYPE_TIMESTAMP) {
-               uint64_t seconds;
+               uint32_t seconds;
                uint32_t nanoseconds;
                uint8_t ts_timescale = GET_U_1(bp);
                bp += 1;
@@ -151,9 +148,9 @@ arista_ethertype_print(netdissect_options *ndo, const u_char *bp, u_int len _U_)
                case FORMAT_48BIT:
                        seconds = GET_BE_U_2(bp);
                        nanoseconds = GET_BE_U_4(bp + 2);
-                       seconds += nanoseconds / 1000000000;
-                       nanoseconds %= 1000000000;
-                       ND_PRINT("%" PRIu64 ".%09u", seconds, nanoseconds);
+                       ND_PRINT("%u.%09u", seconds, nanoseconds);
+                       if (nanoseconds > ND_NANO_PER_SEC - 1)
+                               ND_PRINT(" " ND_INVALID_NANO_SEC_STR);
                        bytesConsumed += 6;
                        break;
                default: