diff options
author | Guy Harris <guy@alum.mit.edu> | 2012-02-26 08:02:02 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2012-02-26 08:02:02 +0000 |
commit | 30b86b78178e111747eaf605925cce289483b98d (patch) | |
tree | 1dd8940d5ab0c55943f42d9126506f21691b3cc5 | |
parent | 08d7ff268bc91be4a210006b1f8ed2dae67c4391 (diff) | |
download | wireshark-30b86b78178e111747eaf605925cce289483b98d.tar.gz wireshark-30b86b78178e111747eaf605925cce289483b98d.tar.bz2 wireshark-30b86b78178e111747eaf605925cce289483b98d.zip |
Suppress invalid or non-meaningful statistics - for example, without
time stamps on all packets in a set, you can't determine the start and
end time of the packets in the set (even one timestampless packet throws
the determination off - was that packet before the first time-stamped or
after the last time-stamped packet, or between them?).
svn path=/trunk/; revision=41187
-rw-r--r-- | summary.c | 88 | ||||
-rw-r--r-- | summary.h | 45 | ||||
-rw-r--r-- | ui/gtk/gsm_map_summary.c | 164 | ||||
-rw-r--r-- | ui/gtk/mtp3_summary.c | 71 | ||||
-rw-r--r-- | ui/gtk/summary_dlg.c | 83 |
5 files changed, 296 insertions, 155 deletions
@@ -43,48 +43,67 @@ tally_frame_data(frame_data *cur_frame, summary_tally *sum_tally) { double cur_time; - cur_time = nstime_to_sec(&cur_frame->abs_ts); - - if (cur_time < sum_tally->start_time) { - sum_tally->start_time = cur_time; - } - if (cur_time > sum_tally->stop_time){ - sum_tally->stop_time = cur_time; - } sum_tally->bytes += cur_frame->pkt_len; if (cur_frame->flags.passed_dfilter){ - if (sum_tally->filtered_count==0){ - sum_tally->filtered_start= cur_time; - sum_tally->filtered_stop = cur_time; - } else { - if (cur_time < sum_tally->filtered_start) { - sum_tally->filtered_start = cur_time; - } - if (cur_time > sum_tally->filtered_stop) { - sum_tally->filtered_stop = cur_time; - } - } sum_tally->filtered_count++; - sum_tally->filtered_bytes += cur_frame->pkt_len ; + sum_tally->filtered_bytes += cur_frame->pkt_len; } if (cur_frame->flags.marked){ - if (sum_tally->marked_count==0){ - sum_tally->marked_start= cur_time; - sum_tally->marked_stop = cur_time; - } else { - if (cur_time < sum_tally->marked_start) { - sum_tally->marked_start = cur_time; - } - if (cur_time > sum_tally->marked_stop) { - sum_tally->marked_stop = cur_time; - } - } sum_tally->marked_count++; - sum_tally->marked_bytes += cur_frame->pkt_len ; + sum_tally->marked_bytes += cur_frame->pkt_len; } if (cur_frame->flags.ignored){ sum_tally->ignored_count++; } + + if (cur_frame->flags.has_ts) { + /* This packet has a time stamp. */ + cur_time = nstime_to_sec(&cur_frame->abs_ts); + + sum_tally->packet_count_ts++; + if (cur_time < sum_tally->start_time) { + sum_tally->start_time = cur_time; + } + if (cur_time > sum_tally->stop_time){ + sum_tally->stop_time = cur_time; + } + if (cur_frame->flags.passed_dfilter){ + sum_tally->filtered_count_ts++; + /* + * If we've seen one filtered packet, this is the first + * one. + */ + if (sum_tally->filtered_count == 1){ + sum_tally->filtered_start= cur_time; + sum_tally->filtered_stop = cur_time; + } else { + if (cur_time < sum_tally->filtered_start) { + sum_tally->filtered_start = cur_time; + } + if (cur_time > sum_tally->filtered_stop) { + sum_tally->filtered_stop = cur_time; + } + } + } + if (cur_frame->flags.marked){ + sum_tally->marked_count_ts++; + /* + * If we've seen one marked packet, this is the first + * one. + */ + if (sum_tally->marked_count == 1){ + sum_tally->marked_start= cur_time; + sum_tally->marked_stop = cur_time; + } else { + if (cur_time < sum_tally->marked_start) { + sum_tally->marked_start = cur_time; + } + if (cur_time > sum_tally->marked_stop) { + sum_tally->marked_stop = cur_time; + } + } + } + } } void @@ -95,14 +114,17 @@ summary_fill_in(capture_file *cf, summary_tally *st) guint32 framenum; wtapng_section_t* shb_inf; + st->packet_count_ts = 0; st->start_time = 0; st->stop_time = 0; st->bytes = 0; st->filtered_count = 0; + st->filtered_count_ts = 0; st->filtered_start = 0; st->filtered_stop = 0; st->filtered_bytes = 0; st->marked_count = 0; + st->marked_count_ts = 0; st->marked_start = 0; st->marked_stop = 0; st->marked_bytes = 0; @@ -194,7 +216,7 @@ summary_fill_in_capture(capture_file *cf,capture_options *capture_opts, summary_ iface.linktype = wtapng_if_descr.link_type; g_array_append_val(st->ifaces, iface); } - g_free(idb_info); + g_free(idb_info); } } #endif @@ -33,45 +33,48 @@ typedef struct iface_options_tag { char *name; char *descr; char *cfilter; - guint64 drops; /* number of packet drops */ + guint64 drops; /* number of packet drops */ gboolean drops_known; /* TRUE if number of packet drops is known */ - gboolean has_snap; /* TRUE if maximum capture packet length is known */ - int snap; /* Maximum captured packet length */ - int linktype; /* wiretap encapsulation type */ + gboolean has_snap; /* TRUE if maximum capture packet length is known */ + int snap; /* Maximum captured packet length */ + int linktype; /* wiretap encapsulation type */ } iface_options; typedef struct _summary_tally { - guint64 bytes; /**< total bytes */ - double start_time; /**< seconds, with msec resolution */ - double stop_time; /**< seconds, with msec resolution */ + guint64 bytes; /**< total bytes */ + double start_time; /**< seconds, with msec resolution */ + double stop_time; /**< seconds, with msec resolution */ double elapsed_time; /**< seconds, with msec resolution, - includes time before first packet - and after last packet */ - int marked_count; /**< number of marked packets */ + includes time before first packet + and after last packet */ + guint32 marked_count; /**< number of marked packets */ + guint32 marked_count_ts; /**< number of time-stamped marked packets */ guint64 marked_bytes; /**< total bytes in the marked packets */ double marked_start; /**< time in seconds, with msec resolution */ double marked_stop; /**< time in seconds, with msec resolution */ - int ignored_count; /**< number of ignored packets */ - int packet_count; /**< total number of packets in trace */ - int filtered_count; /**< number of filtered packets */ + guint32 ignored_count; /**< number of ignored packets */ + guint32 packet_count; /**< total number of packets in trace */ + guint32 packet_count_ts; /**< total number of time-stamped packets in trace */ + guint32 filtered_count; /**< number of filtered packets */ + guint32 filtered_count_ts; /**< number of time-stamped filtered packets */ guint64 filtered_bytes; /**< total bytes in the filtered packets */ double filtered_start; /**< time in seconds, with msec resolution */ double filtered_stop; /**< time in seconds, with msec resolution */ const char *filename; gint64 file_length; /**< file length in bytes */ - int file_type; /**< wiretap file type */ - int encap_type; /**< wiretap encapsulation type */ + int file_type; /**< wiretap file type */ + int encap_type; /**< wiretap encapsulation type */ gboolean has_snap; /**< TRUE if maximum capture packet length is known */ - int snap; /**< Maximum captured packet length */ - gboolean drops_known; /**< TRUE if number of packet drops is known */ + int snap; /**< Maximum captured packet length */ + gboolean drops_known; /**< TRUE if number of packet drops is known */ guint64 drops; /**< number of packet drops */ const char *dfilter; /**< display filter */ gboolean is_tempfile; /* from SHB, use summary_fill_shb_inf() to get values */ - gchar *opt_comment; /**< comment from SHB block */ - gchar *shb_hardware; /**< Capture HW from SHB block */ - gchar *shb_os; /**< The OS the capture was made on from SHB block */ - gchar *shb_user_appl; /**< The application that made the capture from SHB block */ + gchar *opt_comment; /**< comment from SHB block */ + gchar *shb_hardware; /**< Capture HW from SHB block */ + gchar *shb_os; /**< The OS the capture was made on from SHB block */ + gchar *shb_user_appl; /**< The application that made the capture from SHB block */ /* capture related, use summary_fill_in_capture() to get values */ GArray *ifaces; gboolean legacy; diff --git a/ui/gtk/gsm_map_summary.c b/ui/gtk/gsm_map_summary.c index 6651a47661..01c3229a6c 100644 --- a/ui/gtk/gsm_map_summary.c +++ b/ui/gtk/gsm_map_summary.c @@ -90,7 +90,7 @@ void gsm_map_stat_gtk_sum_cb(GtkAction *action _U_, gpointer user_data _U_) /* initialize the tally */ summary_fill_in(&cfile, &summary); - /* initial compututations */ + /* initial computations */ seconds = summary.stop_time - summary.start_time; sum_open_w = dlg_window_new("GSM MAP Statistics: Summary"); /* transient_for top_level */ @@ -138,12 +138,21 @@ void gsm_map_stat_gtk_sum_cb(GtkAction *action _U_, gpointer user_data _U_) gtk_container_add(GTK_CONTAINER(data_fr), data_box); gtk_widget_show(data_box); - /* seconds */ - g_snprintf(string_buff, SUM_STR_MAX, "Elapsed time: %.3f seconds", summary.elapsed_time); - add_string_to_box(string_buff, data_box); - - g_snprintf(string_buff, SUM_STR_MAX, "Between first and last packet: %.3f seconds", seconds); - add_string_to_box(string_buff, data_box); + /* + * We must have no un-time-stamped packets (i.e., the number of + * time-stamped packets must be the same as the number of packets), + * and at least two time-stamped packets, in order for the elapsed + * time to be valid. + */ + if (summary.packet_count_ts == summary.packet_count && + summary.packet_count_ts >= 2) { + /* seconds */ + g_snprintf(string_buff, SUM_STR_MAX, "Elapsed time: %.3f seconds", summary.elapsed_time); + add_string_to_box(string_buff, data_box); + + g_snprintf(string_buff, SUM_STR_MAX, "Between first and last packet: %.3f seconds", seconds); + add_string_to_box(string_buff, data_box); + } /* Packet count */ g_snprintf(string_buff, SUM_STR_MAX, "Packet count: %i", summary.packet_count); @@ -178,12 +187,21 @@ void gsm_map_stat_gtk_sum_cb(GtkAction *action _U_, gpointer user_data _U_) g_snprintf(string_buff, SUM_STR_MAX, "Total number of Invokes: %u", tot_invokes); add_string_to_box(string_buff, invoke_box); - /* Total number of invokes per second */ - if (seconds) - g_snprintf(string_buff, SUM_STR_MAX, "Total number of Invokes per second: %.2f", tot_invokes/seconds); - else - g_snprintf(string_buff, SUM_STR_MAX, "Total number of Invokes per second: N/A"); - add_string_to_box(string_buff, invoke_box); + /* + * We must have no un-time-stamped packets (i.e., the number of + * time-stamped packets must be the same as the number of packets), + * and at least two time-stamped packets, in order for the elapsed + * time to be valid. + */ + if (summary.packet_count_ts == summary.packet_count && + summary.packet_count_ts >= 2) { + /* Total number of invokes per second */ + if (seconds) + g_snprintf(string_buff, SUM_STR_MAX, "Total number of Invokes per second: %.2f", tot_invokes/seconds); + else + g_snprintf(string_buff, SUM_STR_MAX, "Total number of Invokes per second: N/A"); + add_string_to_box(string_buff, invoke_box); + } /* Total size of invokes */ g_snprintf(string_buff, SUM_STR_MAX, "Total number of bytes for Invokes: %.0f", tot_invokes_size); @@ -191,17 +209,26 @@ void gsm_map_stat_gtk_sum_cb(GtkAction *action _U_, gpointer user_data _U_) /* Average size of invokes */ if (tot_invokes) - g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Invoke: %.2f", tot_invokes_size/tot_invokes); + g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Invoke: %.2f", tot_invokes_size/tot_invokes); else - g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Invoke: N/A"); + g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Invoke: N/A"); add_string_to_box(string_buff, invoke_box); - /* Average size of invokes per second */ - if (seconds) - g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: %.2f", tot_invokes_size/seconds); - else - g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: N/A"); - add_string_to_box(string_buff, invoke_box); + /* + * We must have no un-time-stamped packets (i.e., the number of + * time-stamped packets must be the same as the number of packets), + * and at least two time-stamped packets, in order for the elapsed + * time to be valid. + */ + if (summary.packet_count_ts == summary.packet_count && + summary.packet_count_ts >= 2) { + /* Average size of invokes per second */ + if (seconds) + g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: %.2f", tot_invokes_size/seconds); + else + g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: N/A"); + add_string_to_box(string_buff, invoke_box); + } /* Return Results frame */ rr_fr = gtk_frame_new("Return Results"); @@ -216,12 +243,21 @@ void gsm_map_stat_gtk_sum_cb(GtkAction *action _U_, gpointer user_data _U_) g_snprintf(string_buff, SUM_STR_MAX, "Total number of Return Results: %u", tot_rr); add_string_to_box(string_buff, rr_box); - /* Total number of return results per second */ - if (seconds) - g_snprintf(string_buff, SUM_STR_MAX, "Total number of Return Results per second: %.2f", tot_rr/seconds); - else - g_snprintf(string_buff, SUM_STR_MAX, "Total number of Return Results per second: N/A"); - add_string_to_box(string_buff, rr_box); + /* + * We must have no un-time-stamped packets (i.e., the number of + * time-stamped packets must be the same as the number of packets), + * and at least two time-stamped packets, in order for the elapsed + * time to be valid. + */ + if (summary.packet_count_ts == summary.packet_count && + summary.packet_count_ts >= 2) { + /* Total number of return results per second */ + if (seconds) + g_snprintf(string_buff, SUM_STR_MAX, "Total number of Return Results per second: %.2f", tot_rr/seconds); + else + g_snprintf(string_buff, SUM_STR_MAX, "Total number of Return Results per second: N/A"); + add_string_to_box(string_buff, rr_box); + } /* Total size of return results */ g_snprintf(string_buff, SUM_STR_MAX, "Total number of bytes for Return Results: %.0f", tot_rr_size); @@ -229,17 +265,26 @@ void gsm_map_stat_gtk_sum_cb(GtkAction *action _U_, gpointer user_data _U_) /* Average size of return results */ if (tot_rr) - g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Return Result: %.2f", tot_rr_size/tot_rr); + g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Return Result: %.2f", tot_rr_size/tot_rr); else - g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Return Result: N/A"); + g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Return Result: N/A"); add_string_to_box(string_buff, rr_box); - /* Average size of return results per second */ - if (seconds) - g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: %.2f", tot_rr_size/seconds); - else - g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: N/A"); - add_string_to_box(string_buff, rr_box); + /* + * We must have no un-time-stamped packets (i.e., the number of + * time-stamped packets must be the same as the number of packets), + * and at least two time-stamped packets, in order for the elapsed + * time to be valid. + */ + if (summary.packet_count_ts == summary.packet_count && + summary.packet_count_ts >= 2) { + /* Average size of return results per second */ + if (seconds) + g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: %.2f", tot_rr_size/seconds); + else + g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: N/A"); + add_string_to_box(string_buff, rr_box); + } /* Totals frame */ tot_fr = gtk_frame_new("Totals"); @@ -254,30 +299,47 @@ void gsm_map_stat_gtk_sum_cb(GtkAction *action _U_, gpointer user_data _U_) g_snprintf(string_buff, SUM_STR_MAX, "Total number of GSM MAP messages: %u", tot_invokes + tot_rr); add_string_to_box(string_buff, tot_box); - if (seconds) - g_snprintf(string_buff, SUM_STR_MAX, "Total number of GSM MAP messages per second: %.2f", - (tot_invokes + tot_rr)/seconds); - else - g_snprintf(string_buff, SUM_STR_MAX, "Total number of GSM MAP messages per second: N/A"); - add_string_to_box(string_buff, tot_box); + /* + * We must have no un-time-stamped packets (i.e., the number of + * time-stamped packets must be the same as the number of packets), + * and at least two time-stamped packets, in order for the elapsed + * time to be valid. + */ + if (summary.packet_count_ts == summary.packet_count && + summary.packet_count_ts >= 2) { + if (seconds) + g_snprintf(string_buff, SUM_STR_MAX, "Total number of GSM MAP messages per second: %.2f", + (tot_invokes + tot_rr)/seconds); + else + g_snprintf(string_buff, SUM_STR_MAX, "Total number of GSM MAP messages per second: N/A"); + add_string_to_box(string_buff, tot_box); + } g_snprintf(string_buff, SUM_STR_MAX, "Total number of bytes for GSM MAP messages: %.0f", tot_invokes_size + tot_rr_size); add_string_to_box(string_buff, tot_box); if (tot_invokes + tot_rr) - g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per GSM MAP messages: %.2f", - (tot_invokes_size + tot_rr_size)/(tot_invokes + tot_rr)); + g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per GSM MAP messages: %.2f", + (tot_invokes_size + tot_rr_size)/(tot_invokes + tot_rr)); else - g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per GSM MAP messages: N/A"); - add_string_to_box(string_buff, tot_box); - - if (seconds) - g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes second: %.2f", - (tot_invokes_size + tot_rr_size)/seconds); - else - g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes second: N/A"); + g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per GSM MAP messages: N/A"); add_string_to_box(string_buff, tot_box); + /* + * We must have no un-time-stamped packets (i.e., the number of + * time-stamped packets must be the same as the number of packets), + * and at least two time-stamped packets, in order for the elapsed + * time to be valid. + */ + if (summary.packet_count_ts == summary.packet_count && + summary.packet_count_ts >= 2) { + if (seconds) + g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes second: %.2f", + (tot_invokes_size + tot_rr_size)/seconds); + else + g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes second: N/A"); + add_string_to_box(string_buff, tot_box); + } /* Button row. */ bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL); diff --git a/ui/gtk/mtp3_summary.c b/ui/gtk/mtp3_summary.c index 6afa783296..770d3ccbe8 100644 --- a/ui/gtk/mtp3_summary.c +++ b/ui/gtk/mtp3_summary.c @@ -286,7 +286,7 @@ void mtp3_sum_gtk_sum_cb(GtkAction *action _U_, gpointer user_data _U_) /* initialize the tally */ summary_fill_in(&cfile, &summary); - /* initial compututations */ + /* initial computations */ seconds = summary.stop_time - summary.start_time; sum_open_w = dlg_window_new("MTP3 Statistics: Summary"); /* transient_for top_level */ @@ -335,12 +335,21 @@ void mtp3_sum_gtk_sum_cb(GtkAction *action _U_, gpointer user_data _U_) gtk_container_add(GTK_CONTAINER(data_fr), data_box); gtk_widget_show(data_box); - /* seconds */ - g_snprintf(string_buff, SUM_STR_MAX, "Elapsed time: %.3f seconds", summary.elapsed_time); - add_string_to_box(string_buff, data_box); - - g_snprintf(string_buff, SUM_STR_MAX, "Between first and last packet: %.3f seconds", seconds); - add_string_to_box(string_buff, data_box); + /* + * We must have no un-time-stamped packets (i.e., the number of + * time-stamped packets must be the same as the number of packets), + * and at least two time-stamped packets, in order for the elapsed + * time to be valid. + */ + if (summary.packet_count_ts == summary.packet_count && + summary.packet_count_ts >= 2) { + /* seconds */ + g_snprintf(string_buff, SUM_STR_MAX, "Elapsed time: %.3f seconds", summary.elapsed_time); + add_string_to_box(string_buff, data_box); + + g_snprintf(string_buff, SUM_STR_MAX, "Between first and last packet: %.3f seconds", seconds); + add_string_to_box(string_buff, data_box); + } /* Packet count */ g_snprintf(string_buff, SUM_STR_MAX, "Packet count: %i", summary.packet_count); @@ -351,7 +360,7 @@ void mtp3_sum_gtk_sum_cb(GtkAction *action _U_, gpointer user_data _U_) gtk_container_add(GTK_CONTAINER(main_vb), table_fr); gtk_widget_show(table_fr); - table = create_list(); + table = create_list(); gtk_container_add(GTK_CONTAINER(table_fr), table); gtk_widget_show(table); @@ -371,32 +380,50 @@ void mtp3_sum_gtk_sum_cb(GtkAction *action _U_, gpointer user_data _U_) g_snprintf(string_buff, SUM_STR_MAX, "Total MSUs: %u", tot_num_msus); add_string_to_box(string_buff, tot_box); - if (seconds) { - g_snprintf(string_buff, SUM_STR_MAX, "MSUs/second: %.2f", tot_num_msus/seconds); - } - else { - g_snprintf(string_buff, SUM_STR_MAX, "MSUs/second: N/A"); + /* + * We must have no un-time-stamped packets (i.e., the number of + * time-stamped packets must be the same as the number of packets), + * and at least two time-stamped packets, in order for the elapsed + * time to be valid. + */ + if (summary.packet_count_ts == summary.packet_count && + summary.packet_count_ts >= 2) { + if (seconds) { + g_snprintf(string_buff, SUM_STR_MAX, "MSUs/second: %.2f", tot_num_msus/seconds); + } + else { + g_snprintf(string_buff, SUM_STR_MAX, "MSUs/second: N/A"); + } + add_string_to_box(string_buff, tot_box); } - add_string_to_box(string_buff, tot_box); g_snprintf(string_buff, SUM_STR_MAX, "Total Bytes: %.0f", tot_num_bytes); add_string_to_box(string_buff, tot_box); if (tot_num_msus) { - g_snprintf(string_buff, SUM_STR_MAX, "Average Bytes/MSU: %.2f", tot_num_bytes/tot_num_msus); + g_snprintf(string_buff, SUM_STR_MAX, "Average Bytes/MSU: %.2f", tot_num_bytes/tot_num_msus); } else { - g_snprintf(string_buff, SUM_STR_MAX, "Average Bytes/MSU: N/A"); + g_snprintf(string_buff, SUM_STR_MAX, "Average Bytes/MSU: N/A"); } add_string_to_box(string_buff, tot_box); - if (seconds) { - g_snprintf(string_buff, SUM_STR_MAX, "Bytes/second: %.2f", tot_num_bytes/seconds); - } - else { - g_snprintf(string_buff, SUM_STR_MAX, "Bytes/second: N/A"); + /* + * We must have no un-time-stamped packets (i.e., the number of + * time-stamped packets must be the same as the number of packets), + * and at least two time-stamped packets, in order for the elapsed + * time to be valid. + */ + if (summary.packet_count_ts == summary.packet_count && + summary.packet_count_ts >= 2) { + if (seconds) { + g_snprintf(string_buff, SUM_STR_MAX, "Bytes/second: %.2f", tot_num_bytes/seconds); + } + else { + g_snprintf(string_buff, SUM_STR_MAX, "Bytes/second: N/A"); + } + add_string_to_box(string_buff, tot_box); } - add_string_to_box(string_buff, tot_box); /* Button row. */ bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL); diff --git a/ui/gtk/summary_dlg.c b/ui/gtk/summary_dlg.c index 87f8a83424..055f5c2390 100644 --- a/ui/gtk/summary_dlg.c +++ b/ui/gtk/summary_dlg.c @@ -170,6 +170,14 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_) #ifdef HAVE_LIBPCAP summary_fill_in_capture(&cfile, &global_capture_opts, &summary); #endif + /* + * Note: the start and stop times are initialized to 0, so if we + * have zero or one packets of the type in question that have + * time stamps, the elapsed times will be zero, just as if we + * have both start and stop time stamps but they're the same. + * That means we can avoid some checks for whether we have more + * than one packet of the type in question with time stamps. + */ seconds = summary.stop_time - summary.start_time; disp_seconds = summary.filtered_stop - summary.filtered_start; marked_seconds = summary.marked_stop - summary.marked_start; @@ -214,30 +222,43 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_) add_string_to_table(table, &row, "Packet size limit:", string_buff); } - - /* Time */ - add_string_to_table(table, &row, "", ""); - add_string_to_table(table, &row, "Time", ""); - - /* start time */ - time_to_string(string_buff, SUM_STR_MAX, (time_t)summary.start_time); - add_string_to_table(table, &row, "First packet:", string_buff); - - /* stop time */ - time_to_string(string_buff, SUM_STR_MAX, (time_t)summary.stop_time); - add_string_to_table(table, &row, "Last packet:", string_buff); - - /* elapsed seconds */ - elapsed_time = (unsigned int)summary.elapsed_time; - if(elapsed_time/86400) { - g_snprintf(string_buff, SUM_STR_MAX, "%02u days %02u:%02u:%02u", - elapsed_time/86400, elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60); - } else { - g_snprintf(string_buff, SUM_STR_MAX, "%02u:%02u:%02u", - elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60); + /* + * We must have no un-time-stamped packets (i.e., the number of + * time-stamped packets must be the same as the number of packets), + * and at least one time-stamped packet, in order for the start + * and stop times to be valid. + */ + if (summary.packet_count_ts == summary.packet_count && + summary.packet_count >= 1) { + /* Time */ + add_string_to_table(table, &row, "", ""); + add_string_to_table(table, &row, "Time", ""); + + /* start time */ + time_to_string(string_buff, SUM_STR_MAX, (time_t)summary.start_time); + add_string_to_table(table, &row, "First packet:", string_buff); + + /* stop time */ + time_to_string(string_buff, SUM_STR_MAX, (time_t)summary.stop_time); + add_string_to_table(table, &row, "Last packet:", string_buff); + + /* + * We must have at least two time-stamped packets for the elapsed time + * to be valid. + */ + if (summary.packet_count_ts >= 2) { + /* elapsed seconds */ + elapsed_time = (unsigned int)summary.elapsed_time; + if(elapsed_time/86400) { + g_snprintf(string_buff, SUM_STR_MAX, "%02u days %02u:%02u:%02u", + elapsed_time/86400, elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60); + } else { + g_snprintf(string_buff, SUM_STR_MAX, "%02u:%02u:%02u", + elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60); + } + add_string_to_table(table, &row, "Elapsed:", string_buff); + } } - add_string_to_table(table, &row, "Elapsed:", string_buff); - /* Capture */ add_string_to_table(table, &row, "", ""); @@ -395,7 +416,8 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_) } else { string_buff3[0] = '\0'; } - add_string_to_list(list, "Between first and last packet", string_buff, string_buff2, string_buff3); + if (string_buff[0] != '\0' || string_buff2[0] != '\0' || string_buff3[0] != '\0') + add_string_to_list(list, "Between first and last packet", string_buff, string_buff2, string_buff3); /* Packets per second */ if (seconds > 0) { @@ -413,6 +435,7 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_) } else { string_buff3[0] = '\0'; } + if (string_buff[0] != '\0' || string_buff2[0] != '\0' || string_buff3[0] != '\0') add_string_to_list(list, "Avg. packets/sec", string_buff, string_buff2, string_buff3); /* Packet size */ @@ -437,7 +460,8 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_) } else { string_buff3[0] = '\0'; } - add_string_to_list(list, "Avg. packet size", string_buff, string_buff2, string_buff3); + if (string_buff[0] != '\0' || string_buff2[0] != '\0' || string_buff3[0] != '\0') + add_string_to_list(list, "Avg. packet size", string_buff, string_buff2, string_buff3); /* Byte count */ g_snprintf(string_buff, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", summary.bytes); @@ -451,7 +475,8 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_) } else { string_buff3[0] = '\0'; } - add_string_to_list(list, "Bytes", string_buff, string_buff2, string_buff3); + if (string_buff[0] != '\0' || string_buff2[0] != '\0' || string_buff3[0] != '\0') + add_string_to_list(list, "Bytes", string_buff, string_buff2, string_buff3); /* Bytes per second */ if (seconds > 0){ @@ -472,7 +497,8 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_) } else { string_buff3[0] = '\0'; } - add_string_to_list(list, "Avg. bytes/sec", string_buff, string_buff2, string_buff3); + if (string_buff[0] != '\0' || string_buff2[0] != '\0' || string_buff3[0] != '\0') + add_string_to_list(list, "Avg. bytes/sec", string_buff, string_buff2, string_buff3); /* MBit per second */ if (seconds > 0) { @@ -496,7 +522,8 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_) } else { string_buff3[0] = '\0'; } - add_string_to_list(list, "Avg. MBit/sec", string_buff, string_buff2, string_buff3); + if (string_buff[0] != '\0' || string_buff2[0] != '\0' || string_buff3[0] != '\0') + add_string_to_list(list, "Avg. MBit/sec", string_buff, string_buff2, string_buff3); /* Button row. */ |