diff options
author | Guy Harris <guy@alum.mit.edu> | 2018-02-07 00:28:59 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2018-02-07 08:29:52 +0000 |
commit | 40a533abe1cc7c9992a20842ef84cc75dea1dc5a (patch) | |
tree | fe605cc7e852a90e1dd868dd4e276347335740a9 /ui | |
parent | 908e25d5aaba5496e73940709e921f45870b849e (diff) |
Move summary.[ch] to libui.
Change-Id: I49f1eeb4fc3a90e436da116577a7d0c5ba982eee
Reviewed-on: https://code.wireshark.org/review/25657
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/CMakeLists.txt | 1 | ||||
-rw-r--r-- | ui/Makefile.am | 2 | ||||
-rw-r--r-- | ui/gtk/gsm_map_summary.c | 2 | ||||
-rw-r--r-- | ui/gtk/main.c | 2 | ||||
-rw-r--r-- | ui/gtk/mtp3_summary.c | 2 | ||||
-rw-r--r-- | ui/gtk/packet_win.c | 2 | ||||
-rw-r--r-- | ui/gtk/summary_dlg.c | 2 | ||||
-rw-r--r-- | ui/qt/capture_file_properties_dialog.cpp | 2 | ||||
-rw-r--r-- | ui/qt/gsm_map_summary_dialog.cpp | 2 | ||||
-rw-r--r-- | ui/qt/mtp3_summary_dialog.cpp | 3 | ||||
-rw-r--r-- | ui/summary.c | 230 | ||||
-rw-r--r-- | ui/summary.h | 94 |
12 files changed, 335 insertions, 9 deletions
diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt index 9c2bb03584..84a2896549 100644 --- a/ui/CMakeLists.txt +++ b/ui/CMakeLists.txt @@ -50,6 +50,7 @@ set(COMMON_UI_SRC service_response_time.c software_update.c ssl_key_export.c + summary.c tap_export_pdu.c tap-iax2-analysis.c tap-rtp-common.c diff --git a/ui/Makefile.am b/ui/Makefile.am index 9f64a2e2a4..cd341381a6 100644 --- a/ui/Makefile.am +++ b/ui/Makefile.am @@ -75,6 +75,7 @@ WIRESHARK_UI_SRC = \ service_response_time.c \ software_update.c \ ssl_key_export.c \ + summary.c \ tap_export_pdu.c \ tap-iax2-analysis.c \ tap-rlc-graph.c \ @@ -126,6 +127,7 @@ WIRESHARK_UI_INCLUDES = \ simple_dialog.h \ software_update.h \ ssl_key_export.h \ + summary.h \ tap_export_pdu.h \ tap-iax2-analysis.h \ tap-rlc-graph.h \ diff --git a/ui/gtk/gsm_map_summary.c b/ui/gtk/gsm_map_summary.c index e3dcd57d7b..e258889731 100644 --- a/ui/gtk/gsm_map_summary.c +++ b/ui/gtk/gsm_map_summary.c @@ -37,9 +37,9 @@ #include <epan/dissectors/packet-gsm_map.h> #include "globals.h" -#include "summary.h" #include "ui/simple_dialog.h" +#include "ui/summary.h" #include <epan/stat_tap_ui.h> #include "ui/gtk/gui_stat_menu.h" diff --git a/ui/gtk/main.c b/ui/gtk/main.c index e76fa72100..647735e1f3 100644 --- a/ui/gtk/main.c +++ b/ui/gtk/main.c @@ -88,7 +88,6 @@ /* general (not GTK specific) */ #include "../../file.h" #include "../../frame_tvbuff.h" -#include "../../summary.h" #include <epan/color_filters.h> #include "epan/register.h" #include "../../ringbuffer.h" @@ -106,6 +105,7 @@ #include "ui/recent.h" #include "ui/recent_utils.h" #include "ui/software_update.h" +#include "ui/summary.h" #include "ui/ws_ui_util.h" #include "ui/util.h" #include "ui/dissect_opts.h" diff --git a/ui/gtk/mtp3_summary.c b/ui/gtk/mtp3_summary.c index 7e2d4c93c3..79ec05640f 100644 --- a/ui/gtk/mtp3_summary.c +++ b/ui/gtk/mtp3_summary.c @@ -39,9 +39,9 @@ #include <epan/dissectors/packet-mtp3.h> #include "globals.h" -#include "summary.h" #include "ui/simple_dialog.h" +#include "ui/summary.h" #include "ui/gtk/gui_stat_menu.h" #include "ui/gtk/dlg_utils.h" diff --git a/ui/gtk/packet_win.c b/ui/gtk/packet_win.c index 6cf084ac2c..15cd0ddd6b 100644 --- a/ui/gtk/packet_win.c +++ b/ui/gtk/packet_win.c @@ -51,10 +51,10 @@ #include <epan/print.h> #include "../../file.h" -#include "../../summary.h" #include "ui/recent.h" #include "ui/simple_dialog.h" +#include "ui/summary.h" #include "ui/ws_ui_util.h" #include "ui/gtk/font_utils.h" diff --git a/ui/gtk/summary_dlg.c b/ui/gtk/summary_dlg.c index 2a7bfe7f99..6a24690178 100644 --- a/ui/gtk/summary_dlg.c +++ b/ui/gtk/summary_dlg.c @@ -29,7 +29,6 @@ #include <version_info.h> #include "../../file.h" -#include "../../summary.h" #ifdef HAVE_LIBPCAP #include "ui/capture.h" @@ -38,6 +37,7 @@ #include "ui/main_statusbar.h" #include "ui/gtk/main.h" #include "ui/gtk/summary_dlg.h" +#include "ui/summary.h" #include "ui/gtk/dlg_utils.h" #include "ui/gtk/gui_utils.h" #include "ui/gtk/help_dlg.h" diff --git a/ui/qt/capture_file_properties_dialog.cpp b/ui/qt/capture_file_properties_dialog.cpp index dfdb63d49d..d97b4beaa1 100644 --- a/ui/qt/capture_file_properties_dialog.cpp +++ b/ui/qt/capture_file_properties_dialog.cpp @@ -11,7 +11,7 @@ #include "capture_file_properties_dialog.h" #include <ui_capture_file_properties_dialog.h> -#include "summary.h" +#include "ui/summary.h" #include "wsutil/str_util.h" #include "wsutil/utf8_entities.h" diff --git a/ui/qt/gsm_map_summary_dialog.cpp b/ui/qt/gsm_map_summary_dialog.cpp index 52f4cceec0..585f7c36c2 100644 --- a/ui/qt/gsm_map_summary_dialog.cpp +++ b/ui/qt/gsm_map_summary_dialog.cpp @@ -17,7 +17,7 @@ #include <glib.h> -#include "summary.h" +#include "ui/summary.h" #include <epan/packet.h> #include <epan/tap.h> diff --git a/ui/qt/mtp3_summary_dialog.cpp b/ui/qt/mtp3_summary_dialog.cpp index 20a2300342..31d6fdcfdd 100644 --- a/ui/qt/mtp3_summary_dialog.cpp +++ b/ui/qt/mtp3_summary_dialog.cpp @@ -17,8 +17,6 @@ #include <glib.h> -#include "summary.h" - #include <epan/tap.h> #include <epan/dissectors/packet-mtp3.h> @@ -27,6 +25,7 @@ #include "ui/capture_globals.h" #include "ui/simple_dialog.h" +#include "ui/summary.h" #include <ui/qt/utils/qt_ui_utils.h> diff --git a/ui/summary.c b/ui/summary.c new file mode 100644 index 0000000000..99c0fd02bd --- /dev/null +++ b/ui/summary.c @@ -0,0 +1,230 @@ +/* summary.c + * Routines for capture file summary info + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <config.h> + +#include <wiretap/pcap-encap.h> +#include <wiretap/wtap_opttypes.h> +#include <wiretap/pcapng.h> + +#include <epan/packet.h> +#include "cfile.h" +#include "summary.h" + +static void +tally_frame_data(frame_data *cur_frame, summary_tally *sum_tally) +{ + double cur_time; + + sum_tally->bytes += cur_frame->pkt_len; + if (cur_frame->flags.passed_dfilter){ + sum_tally->filtered_count++; + sum_tally->filtered_bytes += cur_frame->pkt_len; + } + if (cur_frame->flags.marked){ + sum_tally->marked_count++; + 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 +summary_fill_in(capture_file *cf, summary_tally *st) +{ + frame_data *first_frame, *cur_frame; + guint32 framenum; + iface_options iface; + guint i; + wtapng_iface_descriptions_t* idb_info; + wtap_block_t wtapng_if_descr; + wtapng_if_descr_mandatory_t *wtapng_if_descr_mand; + wtap_block_t if_stats; + guint64 isb_ifdrop; + char* if_string; + wtapng_if_descr_filter_t* if_filter; + + 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; + st->ignored_count = 0; + + /* initialize the tally */ + if (cf->count != 0) { + first_frame = frame_data_sequence_find(cf->provider.frames, 1); + st->start_time = nstime_to_sec(&first_frame->abs_ts); + st->stop_time = nstime_to_sec(&first_frame->abs_ts); + + for (framenum = 1; framenum <= cf->count; framenum++) { + cur_frame = frame_data_sequence_find(cf->provider.frames, framenum); + tally_frame_data(cur_frame, st); + } + } + + st->filename = cf->filename; + st->file_length = cf->f_datalen; + st->file_type = cf->cd_t; + st->iscompressed = cf->iscompressed; + st->is_tempfile = cf->is_tempfile; + st->file_encap_type = cf->lnk_t; + st->packet_encap_types = cf->linktypes; + st->snap = cf->snap; + st->elapsed_time = nstime_to_sec(&cf->elapsed_time); + st->packet_count = cf->count; + st->drops_known = cf->drops_known; + st->drops = cf->drops; + st->dfilter = cf->dfilter; + + st->ifaces = g_array_new(FALSE, FALSE, sizeof(iface_options)); + idb_info = wtap_file_get_idb_info(cf->provider.wth); + for (i = 0; i < idb_info->interface_data->len; i++) { + wtapng_if_descr = g_array_index(idb_info->interface_data, wtap_block_t, i); + wtapng_if_descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(wtapng_if_descr); + if (wtap_block_get_custom_option_value(wtapng_if_descr, OPT_IDB_FILTER, (void**)&if_filter) == WTAP_OPTTYPE_SUCCESS) { + iface.cfilter = g_strdup(if_filter->if_filter_str); + } else { + iface.cfilter = NULL; + } + if (wtap_block_get_string_option_value(wtapng_if_descr, OPT_IDB_NAME, &if_string) == WTAP_OPTTYPE_SUCCESS) { + iface.name = g_strdup(if_string); + } else { + iface.name = NULL; + } + if (wtap_block_get_string_option_value(wtapng_if_descr, OPT_IDB_DESCR, &if_string) == WTAP_OPTTYPE_SUCCESS) { + iface.descr = g_strdup(if_string); + } else { + iface.descr = NULL; + } + iface.drops_known = FALSE; + iface.drops = 0; + iface.snap = wtapng_if_descr_mand->snap_len; + iface.encap_type = wtapng_if_descr_mand->wtap_encap; + iface.isb_comment = NULL; + if(wtapng_if_descr_mand->num_stat_entries == 1){ + /* dumpcap only writes one ISB, only handle that for now */ + if_stats = g_array_index(wtapng_if_descr_mand->interface_statistics, wtap_block_t, 0); + if (wtap_block_get_uint64_option_value(if_stats, OPT_ISB_IFDROP, &isb_ifdrop) == WTAP_OPTTYPE_SUCCESS) { + iface.drops_known = TRUE; + iface.drops = isb_ifdrop; + } + /* XXX: this doesn't get used, and might need to be g_strdup'ed when it does */ + /* XXX - support multiple comments */ + if (wtap_block_get_nth_string_option_value(if_stats, OPT_COMMENT, 0, &iface.isb_comment) != WTAP_OPTTYPE_SUCCESS) { + iface.isb_comment = NULL; + } + } + g_array_append_val(st->ifaces, iface); + } + g_free(idb_info); +} + +#ifdef HAVE_LIBPCAP +void +summary_fill_in_capture(capture_file *cf,capture_options *capture_opts, summary_tally *st) +{ + iface_options iface; + interface_t *device; + guint i; + + if (st->ifaces->len == 0) { + /* + * XXX - do this only if we have a live capture. + */ + for (i = 0; i < capture_opts->all_ifaces->len; i++) { + device = &g_array_index(capture_opts->all_ifaces, interface_t, i); + if (!device->selected) { + continue; + } + iface.cfilter = g_strdup(device->cfilter); + iface.name = g_strdup(device->name); + iface.descr = g_strdup(device->display_name); + iface.drops_known = cf->drops_known; + iface.drops = cf->drops; + iface.snap = device->snaplen; + iface.encap_type = wtap_pcap_encap_to_wtap_encap(device->active_dlt); + g_array_append_val(st->ifaces, iface); + } + } +} +#endif + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local Variables: + * c-basic-offset: 2 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=2 tabstop=8 expandtab: + * :indentSize=2:tabSize=8:noTabs=true: + */ diff --git a/ui/summary.h b/ui/summary.h new file mode 100644 index 0000000000..e4cbbcdc82 --- /dev/null +++ b/ui/summary.h @@ -0,0 +1,94 @@ +/* summary.h + * Definitions for capture file summary data + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef __SUMMARY_H__ +#define __SUMMARY_H__ + +#ifdef HAVE_LIBPCAP +#include "ui/capture.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef struct iface_options_tag { + char *name; + char *descr; + char *cfilter; + char *isb_comment; + guint64 drops; /**< number of packet drops */ + gboolean drops_known; /**< TRUE if number of packet drops is known */ + int snap; /**< Maximum captured packet length; 0 if not known */ + int encap_type; /**< 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 */ + double elapsed_time; /**< seconds, with msec resolution, + 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 */ + 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 iscompressed; /**< TRUE if file is compressed */ + int file_encap_type; /**< wiretap encapsulation type for file */ + GArray *packet_encap_types; /**< wiretap encapsulation types for packets */ + int snap; /**< Maximum captured packet length; 0 if not known */ + 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; + /* capture related, use summary_fill_in_capture() to get values */ + GArray *ifaces; + gboolean legacy; +} summary_tally; + +extern void +summary_fill_in(capture_file *cf, summary_tally *st); + +#ifdef HAVE_LIBPCAP +extern void +summary_fill_in_capture(capture_file *cf, capture_options *capture_opts, summary_tally *st); +#endif + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* summary.h */ + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local Variables: + * c-basic-offset: 2 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=2 tabstop=8 expandtab: + * :indentSize=2:tabSize=8:noTabs=true: + */ |