summaryrefslogtreecommitdiff
path: root/capinfos.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-02-28 01:13:41 -0800
committerGuy Harris <guy@alum.mit.edu>2015-02-28 09:15:10 +0000
commit5892d3c42fd29f7c44520978e6cc17c116fb4985 (patch)
tree3a680ebcb9f62eebc61bd6a17a25067113ded659 /capinfos.c
parent65303efe4da5325a4d4db9c389f2dfb09a55eecc (diff)
downloadwireshark-5892d3c42fd29f7c44520978e6cc17c116fb4985.tar.gz
Don't use ctime().
The API checks warn about it being deprecated - that doesn't seem to cause a problem with the buildbot, but does result in failures from the Petri dish. Format the first and last packet time in an ISO 8601-style format. Call them "First packet time" and "Last packet time", rather than "Start time" and "End time", as they're not necessarily the times when the capture started or ended. (Both make the output a bit more like the Statistics -> Summary window.) Change-Id: Ibf02999851f49c7951c6f6152c70efa271414bd9 Reviewed-on: https://code.wireshark.org/review/7442 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'capinfos.c')
-rw-r--r--capinfos.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/capinfos.c b/capinfos.c
index ae3e04f2b1..bc2e73c0b4 100644
--- a/capinfos.c
+++ b/capinfos.c
@@ -403,8 +403,8 @@ static gchar *
time_string(time_t timer, capture_info *cf_info, gboolean want_lf)
{
const gchar *lf = want_lf ? "\n" : "";
- static gchar time_string_buf[20];
- char *time_string_ctime;
+ static gchar time_string_buf[4+1+2+1+2+1+2+1+2+1+2+1+1];
+ struct tm *ti_tm;
if (cf_info->times_known && cf_info->packet_count > 0) {
if (time_as_secs) {
@@ -412,20 +412,21 @@ time_string(time_t timer, capture_info *cf_info, gboolean want_lf)
g_snprintf(time_string_buf, 20, "%lu%s", (unsigned long)timer, lf);
return time_string_buf;
} else {
- time_string_ctime = ctime(&timer);
- if (time_string_ctime == NULL) {
+ ti_tm = localtime(&timer);
+ if (ti_tm == NULL) {
g_snprintf(time_string_buf, 20, "Not representable%s", lf);
return time_string_buf;
}
- if (!want_lf) {
- /*
- * The ctime() function returns a string formatted as:
- * "Www Mmm dd hh:mm:ss yyyy\n"
- * The unwanted '\n' is the 24th character.
- */
- time_string_ctime[24] = '\0';
- }
- return time_string_ctime;
+ g_snprintf(time_string_buf, sizeof time_string_buf,
+ "%04d-%02d-%02d %02d:%02d:%02d%s",
+ ti_tm->tm_year + 1900,
+ ti_tm->tm_mon + 1,
+ ti_tm->tm_mday,
+ ti_tm->tm_hour,
+ ti_tm->tm_min,
+ ti_tm->tm_sec,
+ lf);
+ return time_string_buf;
}
}
@@ -511,9 +512,9 @@ print_stats(const gchar *filename, capture_info *cf_info)
if (cap_duration) /* XXX - shorten to hh:mm:ss */
print_value("Capture duration: ", 0, " seconds", cf_info->duration);
if (cap_start_time)
- printf ("Start time: %s", time_string(start_time_t, cf_info, TRUE));
+ printf ("First packet time: %s", time_string(start_time_t, cf_info, TRUE));
if (cap_end_time)
- printf ("End time: %s", time_string(stop_time_t, cf_info, TRUE));
+ printf ("Last packet time: %s", time_string(stop_time_t, cf_info, TRUE));
if (cap_data_rate_byte) {
printf ("Data byte rate: ");
if (machine_readable) {