#include "wsgetopt.h"
#endif
+#include "svnversion.h"
+
/*
* By default capinfos now continues processing
* the next filename if and when wiretap detects
static gboolean cap_duration = TRUE; /* Report capture duration */
static gboolean cap_start_time = TRUE; /* Report capture start time */
static gboolean cap_end_time = TRUE; /* Report capture end time */
+static gboolean time_as_secs = FALSE; /* Report time values as raw seconds */
static gboolean cap_data_rate_byte = TRUE; /* Report data rate bytes/sec */
static gboolean cap_data_rate_bit = TRUE; /* Report data rate bites/sec */
return(time_string);
}
+static gchar *
+time_string(const time_t *timer, capture_info *cf_info, gboolean want_lf)
+{
+ const gchar *lf = want_lf ? "\n" : "";
+ static gchar time_string_buf[15];
+
+ if (cf_info->packet_count > 0) {
+ if (time_as_secs) {
+ /* XXX - Would it be useful to show sub-second precision? */
+ g_snprintf(time_string_buf, 15, "%lu%s", (unsigned long) *timer, lf);
+ return time_string_buf;
+ } else if (want_lf) {
+ return ctime(timer);
+ } else {
+ return ctime_no_lf(timer);
+ }
+ }
+
+ g_snprintf(time_string_buf, 15, "n/a%s", lf);
+ return time_string_buf;
+}
+
static double
secs_nsecs(const struct wtap_nstime * nstime)
{
return (nstime->nsecs / 1000000000.0) + (double)nstime->secs;
}
-static void print_value(gchar *text_p1, gint width, gchar *text_p2, double value) {
+static void print_value(const gchar *text_p1, gint width, const gchar *text_p2, double value) {
if (value > 0.0)
printf("%s%.*f%s\n", text_p1, width, value, text_p2);
else
if (cap_file_size) printf ("File size: %" G_GINT64_MODIFIER "d bytes\n", cf_info->filesize);
if (cap_data_size) printf ("Data size: %" G_GINT64_MODIFIER "u bytes\n", cf_info->packet_bytes);
if (cap_duration) print_value("Capture duration: ", 0, " seconds", cf_info->duration);
- if (cap_start_time) printf ("Start time: %s", (cf_info->packet_count>0) ? ctime (&start_time_t) : "n/a\n");
- if (cap_end_time) printf ("End time: %s", (cf_info->packet_count>0) ? ctime (&stop_time_t) : "n/a\n");
+ if (cap_start_time) printf ("Start 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));
if (cap_data_rate_byte) print_value("Data byte rate: ", 2, " bytes/sec", cf_info->data_rate);
if (cap_data_rate_bit) print_value("Data bit rate: ", 2, " bits/sec", cf_info->data_rate*8);
if (cap_packet_size) printf ("Average packet size: %.2f bytes\n", cf_info->packet_size);
}
static void
-print_stats_table_header_label(gchar *label)
+print_stats_table_header_label(const gchar *label)
{
putsep();
putquote();
if (cap_start_time) {
putsep();
putquote();
- printf("%s", (cf_info->packet_count>0) ? ctime_no_lf (&start_time_t) : "n/a");
+ printf("%s", time_string(&start_time_t, cf_info, FALSE));
putquote();
}
if (cap_end_time) {
putsep();
putquote();
- printf("%s", (cf_info->packet_count>0) ? ctime_no_lf (&stop_time_t) : "n/a");
+ printf("%s", time_string(&stop_time_t, cf_info, FALSE));
putquote();
}
fprintf(output, " -u display the capture duration (in seconds)\n");
fprintf(output, " -a display the capture start time\n");
fprintf(output, " -e display the capture end time\n");
+ fprintf(output, " -S display start and end times as seconds\n");
fprintf(output, "\n");
fprintf(output, "Statistic infos:\n");
fprintf(output, " -y display average data rate (in bytes/sec)\n");
/* Process the options */
- while ((opt = getopt(argc, argv, "tEcs" FILE_HASH_OPT "duaeyizvhxCALTRrNqQBmb")) !=-1) {
+ while ((opt = getopt(argc, argv, "tEcs" FILE_HASH_OPT "duaeyizvhxCALTRrSNqQBmb")) !=-1) {
switch (opt) {
cap_end_time = TRUE;
break;
+ case 'S':
+ time_as_secs = TRUE;
+ break;
+
case 'y':
if (report_all_infos) disable_all_infos();
cap_data_rate_byte = TRUE;
gcry_md_enable(hd, GCRY_MD_RMD160);
gcry_md_enable(hd, GCRY_MD_MD5);
}
- hash_buf = g_malloc(HASH_BUF_SIZE);
+ hash_buf = (char *)g_malloc(HASH_BUF_SIZE);
}
#endif
hash_to_str(gcry_md_read(hd, GCRY_MD_RMD160), HASH_SIZE_RMD160, file_rmd160);
hash_to_str(gcry_md_read(hd, GCRY_MD_MD5), HASH_SIZE_MD5, file_md5);
}
- fclose(fh);
- gcry_md_reset(hd);
+ if (fh) fclose(fh);
+ if (hd) gcry_md_reset(hd);
}
#endif /* HAVE_LIBGCRYPT */