In timeval-operations.h for microseconds and nanoseconds define both the
maximum number of units per second and the string to use for reporting
an invalid value. Use the new macros in ts_frac_print() and update a
test.
For consistency in print-arista.c instead of MAX_VALID_NS and
BOGUS_NS_STR use the macros from timeval-operations.h.
#include "netdissect.h"
#include "extract.h"
#include "netdissect.h"
#include "extract.h"
+#include "timeval-operations.h"
-#define MAX_VALID_NS 999999999U
-#define BOGUS_NS_STR "(bogus ns!)"
-
static inline void
arista_print_date_hms_time(netdissect_options *ndo, const uint32_t seconds,
const uint32_t nanoseconds)
static inline void
arista_print_date_hms_time(netdissect_options *ndo, const uint32_t seconds,
const uint32_t nanoseconds)
ND_PRINT("%s.%09u",
nd_format_time(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S",
gmtime(&ts)), nanoseconds);
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);
+ if (nanoseconds > ND_NANO_PER_SEC - 1)
+ ND_PRINT(" " ND_INVALID_NANO_SEC_STR);
seconds = GET_BE_U_2(bp);
nanoseconds = GET_BE_U_4(bp + 2);
ND_PRINT("%u.%09u", seconds, nanoseconds);
seconds = GET_BE_U_2(bp);
nanoseconds = GET_BE_U_4(bp + 2);
ND_PRINT("%u.%09u", seconds, nanoseconds);
- if (nanoseconds > MAX_VALID_NS)
- ND_PRINT(" " BOGUS_NS_STR);
+ if (nanoseconds > ND_NANO_PER_SEC - 1)
+ ND_PRINT(" " ND_INVALID_NANO_SEC_STR);
bytesConsumed += 6;
break;
default:
bytesConsumed += 6;
break;
default:
1 17:16:09.999999 IP 131.155.215.69.46656 > 137.116.81.94.80: tcp 0
1 17:16:09.999999 IP 131.155.215.69.46656 > 137.116.81.94.80: tcp 0
- 2 17:16:10.1000000 (invalid ms) IP 137.116.81.94.80 > 131.155.215.69.46656: tcp 0
- 3 17:16:10.2147483648 (invalid ms) IP 131.155.215.69.46656 > 137.116.81.94.80: tcp 0
+ 2 17:16:10.1000000 (invalid us) IP 137.116.81.94.80 > 131.155.215.69.46656: tcp 0
+ 3 17:16:10.2147483648 (invalid us) IP 131.155.215.69.46656 > 137.116.81.94.80: tcp 0
#define ND_MICRO_PER_SEC 1000000
#define ND_NANO_PER_SEC 1000000000
#define ND_MICRO_PER_SEC 1000000
#define ND_NANO_PER_SEC 1000000000
+#define ND_INVALID_MICRO_SEC_STR "(invalid us)"
+#define ND_INVALID_NANO_SEC_STR "(invalid ns)"
#define netdissect_timevalclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
#define netdissect_timevalclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
case PCAP_TSTAMP_PRECISION_MICRO:
ND_PRINT(".%06u", (unsigned)tv->tv_usec);
if ((unsigned)tv->tv_usec > ND_MICRO_PER_SEC - 1)
case PCAP_TSTAMP_PRECISION_MICRO:
ND_PRINT(".%06u", (unsigned)tv->tv_usec);
if ((unsigned)tv->tv_usec > ND_MICRO_PER_SEC - 1)
- ND_PRINT(" (invalid ms)");
+ 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)
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(" (invalid ns)");
+ ND_PRINT(" " ND_INVALID_NANO_SEC_STR);
#else
ND_PRINT(".%06u", (unsigned)tv->tv_usec);
if ((unsigned)tv->tv_usec > ND_MICRO_PER_SEC - 1)
#else
ND_PRINT(".%06u", (unsigned)tv->tv_usec);
if ((unsigned)tv->tv_usec > ND_MICRO_PER_SEC - 1)
- ND_PRINT(" (invalid ms)");
+ ND_PRINT(" " ND_INVALID_MICRO_SEC_STR);