Skip to content

Commit 09512cf

Browse files
committed
Report invalid microseconds as "us", not "ms".
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.
1 parent 584c7c4 commit 09512cf

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

print-arista.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "netdissect.h"
1010
#include "extract.h"
11+
#include "timeval-operations.h"
1112

1213
/*
1314
@@ -85,9 +86,6 @@ static const struct tok hw_info_str[] = {
8586
{ 0, NULL }
8687
};
8788

88-
#define MAX_VALID_NS 999999999U
89-
#define BOGUS_NS_STR "(bogus ns!)"
90-
9189
static inline void
9290
arista_print_date_hms_time(netdissect_options *ndo, const uint32_t seconds,
9391
const uint32_t nanoseconds)
@@ -98,8 +96,8 @@ arista_print_date_hms_time(netdissect_options *ndo, const uint32_t seconds,
9896
ND_PRINT("%s.%09u",
9997
nd_format_time(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S",
10098
gmtime(&ts)), nanoseconds);
101-
if (nanoseconds > MAX_VALID_NS)
102-
ND_PRINT(" " BOGUS_NS_STR);
99+
if (nanoseconds > ND_NANO_PER_SEC - 1)
100+
ND_PRINT(" " ND_INVALID_NANO_SEC_STR);
103101
}
104102

105103
int
@@ -151,8 +149,8 @@ arista_ethertype_print(netdissect_options *ndo, const u_char *bp, u_int len _U_)
151149
seconds = GET_BE_U_2(bp);
152150
nanoseconds = GET_BE_U_4(bp + 2);
153151
ND_PRINT("%u.%09u", seconds, nanoseconds);
154-
if (nanoseconds > MAX_VALID_NS)
155-
ND_PRINT(" " BOGUS_NS_STR);
152+
if (nanoseconds > ND_NANO_PER_SEC - 1)
153+
ND_PRINT(" " ND_INVALID_NANO_SEC_STR);
156154
bytesConsumed += 6;
157155
break;
158156
default:

tests/timestamp_invalid_micro.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
1 17:16:09.999999 IP 131.155.215.69.46656 > 137.116.81.94.80: tcp 0
2-
2 17:16:10.1000000 (invalid ms) IP 137.116.81.94.80 > 131.155.215.69.46656: tcp 0
3-
3 17:16:10.2147483648 (invalid ms) IP 131.155.215.69.46656 > 137.116.81.94.80: tcp 0
2+
2 17:16:10.1000000 (invalid us) IP 137.116.81.94.80 > 131.155.215.69.46656: tcp 0
3+
3 17:16:10.2147483648 (invalid us) IP 131.155.215.69.46656 > 137.116.81.94.80: tcp 0

timeval-operations.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
#define ND_MICRO_PER_SEC 1000000
3434
#define ND_NANO_PER_SEC 1000000000
35+
#define ND_INVALID_MICRO_SEC_STR "(invalid us)"
36+
#define ND_INVALID_NANO_SEC_STR "(invalid ns)"
3537

3638
#define netdissect_timevalclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
3739

util-print.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,13 @@ ts_frac_print(netdissect_options *ndo, const struct timeval *tv)
217217
case PCAP_TSTAMP_PRECISION_MICRO:
218218
ND_PRINT(".%06u", (unsigned)tv->tv_usec);
219219
if ((unsigned)tv->tv_usec > ND_MICRO_PER_SEC - 1)
220-
ND_PRINT(" (invalid ms)");
220+
ND_PRINT(" " ND_INVALID_MICRO_SEC_STR);
221221
break;
222222

223223
case PCAP_TSTAMP_PRECISION_NANO:
224224
ND_PRINT(".%09u", (unsigned)tv->tv_usec);
225225
if ((unsigned)tv->tv_usec > ND_NANO_PER_SEC - 1)
226-
ND_PRINT(" (invalid ns)");
226+
ND_PRINT(" " ND_INVALID_NANO_SEC_STR);
227227
break;
228228

229229
default:
@@ -233,7 +233,7 @@ ts_frac_print(netdissect_options *ndo, const struct timeval *tv)
233233
#else
234234
ND_PRINT(".%06u", (unsigned)tv->tv_usec);
235235
if ((unsigned)tv->tv_usec > ND_MICRO_PER_SEC - 1)
236-
ND_PRINT(" (invalid ms)");
236+
ND_PRINT(" " ND_INVALID_MICRO_SEC_STR);
237237
#endif
238238
}
239239

0 commit comments

Comments
 (0)