Skip to content

Commit dab871e

Browse files
fxlbguyharris
authored andcommitted
Fix incompatible pointer types with time functions calls on Windows
On Windows in a struct timestamp, tv_sec is a long not a 64-bit time_t. The problem shows: listening on \Device\NPF_Loopback, link-type NULL (BSD loopback), snapshot length 262144 bytes 1 [localtime() or gmtime() couldn't convert the date and time].052255 IP 10.0.0.10 > 224.0.0.251: igmp v2 report 224.0.0.251 2 [localtime() or gmtime() couldn't convert the date and time].792000 IP 10.0.0.10.138 > 10.0.0.255.138: NBT UDP PACKET(138) The warnings with clang-cl were: util-print.c(253,18): warning: incompatible pointer types passing 'const long *' to parameter of type 'const time_t *' (aka 'const long long *') [-Wincompatible-pointer-types] 253 | tm = localtime(&tv->tv_sec); | ^~~~~~~~~~~ util-print.c(255,15): warning: incompatible pointer types passing 'const long *' to parameter of type 'const time_t *' (aka 'const long long *') [-Wincompatible-pointer-types] 255 | tm = gmtime(&tv->tv_sec); | ^~~~~~~~~~~
1 parent ef765a0 commit dab871e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

util-print.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,32 @@ ts_date_hmsfrac_print(netdissect_options *ndo, const struct timeval *tv,
243243
struct tm *tm;
244244
char timebuf[32];
245245
const char *timestr;
246+
#ifdef _WIN32
247+
time_t sec;
248+
#endif
246249

247250
if (tv->tv_sec < 0) {
248251
ND_PRINT("[timestamp < 1970-01-01 00:00:00 UTC]");
249252
return;
250253
}
251254

255+
#ifdef _WIN32
256+
/* on Windows tv->tv_sec is a long not a 64-bit time_t. */
257+
sec = tv->tv_sec;
258+
#endif
259+
252260
if (time_flag == LOCAL_TIME)
261+
#ifdef _WIN32
262+
tm = localtime(&sec);
263+
#else
253264
tm = localtime(&tv->tv_sec);
265+
#endif
254266
else
267+
#ifdef _WIN32
268+
tm = gmtime(&sec);
269+
#else
255270
tm = gmtime(&tv->tv_sec);
271+
#endif
256272

257273
if (date_flag == WITH_DATE) {
258274
timestr = nd_format_time(timebuf, sizeof(timebuf),

0 commit comments

Comments
 (0)