#include "interface.h"
+/*
+ * timestamp display buffer size, the biggest size of both formats is needed
+ * sizeof("0000000000.000000000") > sizeof("00:00:00.000000000")
+ */
+#define TS_BUF_SIZE sizeof("0000000000.000000000")
+
/*
* Print out a null-terminated filename (or other ascii string).
* If ep is NULL, assume no truncation check is needed.
#ifndef HAVE_PCAP_SET_TSTAMP_PRECISION
_U_
#endif
-, int sec, int usec)
+, int sec, int usec, char *buf)
{
- static char buf[sizeof("00:00:00.000000000")];
const char *format;
#ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
break;
default:
- format = "%02d:%02d:%02d.{unknown precision}";
+ format = "%02d:%02d:%02d.{unknown}";
break;
}
#else
format = "%02d:%02d:%02d.%06u";
#endif
- snprintf(buf, sizeof(buf), format,
+ snprintf(buf, TS_BUF_SIZE, format,
sec / 3600, (sec % 3600) / 60, sec % 60, usec);
return buf;
static unsigned b_usec;
int d_usec;
int d_sec;
+ char buf[TS_BUF_SIZE];
switch (ndo->ndo_tflag) {
case 0: /* Default */
s = (tvp->tv_sec + thiszone) % 86400;
- ND_PRINT((ndo, "%s ", ts_format(ndo, s, tvp->tv_usec)));
+ ND_PRINT((ndo, "%s ", ts_format(ndo, s, tvp->tv_usec, buf)));
break;
case 1: /* No time stamp */
d_sec--;
}
- ND_PRINT((ndo, "%s ", ts_format(ndo, d_sec, d_usec)));
+ ND_PRINT((ndo, "%s ", ts_format(ndo, d_sec, d_usec, buf)));
if (ndo->ndo_tflag == 3) { /* set timestamp for last packet */
b_sec = tvp->tv_sec;
}
break;
- case 4: /* Default + Date*/
+ case 4: /* Default + Date */
s = (tvp->tv_sec + thiszone) % 86400;
Time = (tvp->tv_sec + thiszone) - s;
tm = gmtime (&Time);
else
ND_PRINT((ndo, "%04d-%02d-%02d %s ",
tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
- ts_format(ndo, s, tvp->tv_usec)));
+ ts_format(ndo, s, tvp->tv_usec, buf)));
break;
}
}