From: Denis Ovsienko Date: Sun, 10 Mar 2024 16:24:40 +0000 (+0000) Subject: Rearrange seconds and nanoseconds in print-arista.c. X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/3d6e426b5aaf04f4e3ef8074ea38ef7efa87d027?ds=inline Rearrange seconds and nanoseconds in print-arista.c. ./print-arista.c:146:36: warning: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32] When the nanoseconds value is not less that one second, instead of silently carrying the excess over to the seconds value flag the timestamp as bogus, this way the decoder better shows what is on the wire and the seconds value always fits into 32 bits. (cherry picked from commit 8db1e99788bcc493d5d2857e94844e1661caabd1) --- diff --git a/print-arista.c b/print-arista.c index 6d00956a..1f6b0263 100644 --- a/print-arista.c +++ b/print-arista.c @@ -85,18 +85,21 @@ static const struct tok hw_info_str[] = { { 0, NULL } }; +#define MAX_VALID_NS 999999999U +#define BOGUS_NS_STR "(bogus ns!)" + 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; + const time_t ts = seconds; char buf[sizeof("-yyyyyyyyyy-mm-dd hh:mm:ss")]; - ts = seconds + (nanoseconds / 1000000000); - nanoseconds %= 1000000000; ND_PRINT("%s.%09u", nd_format_time(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", gmtime(&ts)), nanoseconds); + if (nanoseconds > MAX_VALID_NS) + ND_PRINT(" " BOGUS_NS_STR); } int @@ -117,7 +120,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; @@ -147,9 +150,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 > MAX_VALID_NS) + ND_PRINT(" " BOGUS_NS_STR); bytesConsumed += 6; break; default: