summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2015-12-19 10:11:40 -0500
committerAnders Broman <a.broman58@gmail.com>2015-12-22 05:23:06 +0000
commitf2b8504740f3fd145a5504682c3788947e151606 (patch)
treecf82793b5becca1f2cd0d2064d3c361e8fe46b7e
parentebb7e000c6b4f2c954923ae26a57a36b665232c1 (diff)
downloadwireshark-f2b8504740f3fd145a5504682c3788947e151606.tar.gz
Don't limit capture packet counts to a fixed set of protocols.
Kept backwards compatibility with GTK+ capture info dialog by keeping the protocols tracked hardcoded, but Qt should have more freedom. Change-Id: I497be71ec761d53f312e14858daa7152d01b8c72 Reviewed-on: https://code.wireshark.org/review/12724 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--capture_info.c32
-rw-r--r--capture_info.h12
-rw-r--r--epan/capture_dissectors.c27
-rw-r--r--epan/capture_dissectors.h4
-rw-r--r--epan/dissectors/packet-arcnet.c7
-rw-r--r--epan/dissectors/packet-arp.c2
-rw-r--r--epan/dissectors/packet-gre.c2
-rw-r--r--epan/dissectors/packet-i2c.c11
-rw-r--r--epan/dissectors/packet-icmp.c2
-rw-r--r--epan/dissectors/packet-icmpv6.c2
-rw-r--r--epan/dissectors/packet-ip.c1
-rw-r--r--epan/dissectors/packet-ipv6.c2
-rw-r--r--epan/dissectors/packet-ipx.c2
-rw-r--r--epan/dissectors/packet-netbios.c3
-rw-r--r--epan/dissectors/packet-ospf.c2
-rw-r--r--epan/dissectors/packet-sctp.c2
-rw-r--r--epan/dissectors/packet-tcp.c2
-rw-r--r--epan/dissectors/packet-udp.c2
-rw-r--r--epan/dissectors/packet-vines.c5
-rw-r--r--epan/packet.h27
-rw-r--r--ui/gtk/capture_info_dlg.c196
21 files changed, 201 insertions, 144 deletions
diff --git a/capture_info.c b/capture_info.c
index 3eafb10bf1..5b0836c04c 100644
--- a/capture_info.c
+++ b/capture_info.c
@@ -38,20 +38,14 @@
/* open the info */
void capture_info_open(capture_session *cap_session, info_data_t* cap_info)
{
- cap_info->counts.total = 0;
- cap_info->counts.sctp = 0;
- cap_info->counts.tcp = 0;
- cap_info->counts.udp = 0;
- cap_info->counts.icmp = 0;
- cap_info->counts.ospf = 0;
- cap_info->counts.gre = 0;
- cap_info->counts.ipx = 0;
- cap_info->counts.netbios = 0;
- cap_info->counts.vines = 0;
- cap_info->counts.other = 0;
- cap_info->counts.arp = 0;
- cap_info->counts.i2c_event = 0;
- cap_info->counts.i2c_data = 0;
+ if (cap_info->counts.counts_hash != NULL)
+ {
+ /* Clean up any previous lists of packet counts */
+ g_hash_table_destroy(cap_info->counts.counts_hash);
+ }
+ cap_info->counts.counts_hash = g_hash_table_new_full( g_direct_hash, g_direct_equal, NULL, g_free );
+ cap_info->counts.other = 0;
+ cap_info->counts.total = 0;
cap_info->wtap = NULL;
cap_info->ui.counts = &cap_info->counts;
@@ -184,16 +178,16 @@ gboolean capture_info_new_file(const char *new_filename, info_data_t* cap_info)
}
static void
-capture_info_packet(packet_counts *counts, gint wtap_linktype, const guchar *pd, guint32 caplen, union wtap_pseudo_header *pseudo_header)
+capture_info_packet(info_data_t* cap_info, gint wtap_linktype, const guchar *pd, guint32 caplen, union wtap_pseudo_header *pseudo_header)
{
capture_packet_info_t cpinfo;
/* Setup the capture packet structure */
- cpinfo.counts = counts;
+ cpinfo.counts = cap_info->counts.counts_hash;
- counts->total++;
+ cap_info->counts.total++;
if (!try_capture_dissector("wtap_encap", wtap_linktype, pd, 0, caplen, &cpinfo, pseudo_header))
- counts->other++;
+ cap_info->counts.other++;
}
/* new packets arrived */
@@ -220,7 +214,7 @@ void capture_info_new_packets(int to_read, info_data_t* cap_info)
wtap_linktype = phdr->pkt_encap;
buf = wtap_buf_ptr(cap_info->wtap);
- capture_info_packet(&cap_info->counts, wtap_linktype, buf, phdr->caplen, pseudo_header);
+ capture_info_packet(cap_info, wtap_linktype, buf, phdr->caplen, pseudo_header);
/*g_warning("new packet");*/
to_read--;
diff --git a/capture_info.h b/capture_info.h
index abc0b2e91f..8e2e7b6bed 100644
--- a/capture_info.h
+++ b/capture_info.h
@@ -39,13 +39,17 @@
#include "capture_opts.h"
#include <capchild/capture_session.h>
-/* XXX - Should be temporary until packet_counts is removed */
-#include <epan/packet.h>
-
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
+typedef struct {
+ GHashTable* counts_hash; /* packet counters keyed by proto */
+ gint other; /* Packets not counted in the hash total */
+ gint total; /* Cache of total packets */
+
+} packet_counts;
+
/** Current Capture info. */
typedef struct {
/* handle */
@@ -58,7 +62,7 @@ typedef struct {
} capture_info;
typedef struct _info_data {
- packet_counts counts; /* several packet type counters */
+ packet_counts counts; /* Packet counting */
struct wtap* wtap; /* current wtap file */
capture_info ui; /* user interface data */
} info_data_t;
diff --git a/epan/capture_dissectors.c b/epan/capture_dissectors.c
index a68d76f4cb..1692533682 100644
--- a/epan/capture_dissectors.c
+++ b/epan/capture_dissectors.c
@@ -39,6 +39,11 @@ struct capture_dissector_handle
protocol_t* protocol;
};
+typedef struct capture_dissector_count
+{
+ guint32 count;
+} capture_dissector_count_t;
+
static GHashTable *capture_dissector_tables = NULL;
static void
@@ -116,6 +121,28 @@ gboolean try_capture_dissector(const char* name, const guint32 pattern, const gu
return handle->dissector(pd, offset, len, cpinfo, pseudo_header);
}
+guint32 capture_dissector_get_count(packet_counts* counts, const int proto)
+{
+ capture_dissector_count_t* hash_count = (capture_dissector_count_t*)g_hash_table_lookup(counts->counts_hash, GUINT_TO_POINTER(proto));
+ if (hash_count == NULL)
+ return 0;
+
+ return hash_count->count;
+}
+
+void capture_dissector_increment_count(capture_packet_info_t *cpinfo, const int proto)
+{
+ /* See if we already have a counter for the protocol */
+ capture_dissector_count_t* hash_count = (capture_dissector_count_t*)g_hash_table_lookup(cpinfo->counts, GUINT_TO_POINTER(proto));
+ if (hash_count == NULL)
+ {
+ hash_count = g_new0(capture_dissector_count_t, 1);
+ g_hash_table_insert(cpinfo->counts, GUINT_TO_POINTER(proto), (gpointer)hash_count);
+ }
+
+ hash_count->count++;
+}
+
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
diff --git a/epan/capture_dissectors.h b/epan/capture_dissectors.h
index 8d353d88f6..dd0486efdf 100644
--- a/epan/capture_dissectors.h
+++ b/epan/capture_dissectors.h
@@ -25,6 +25,7 @@
#include "ws_symbol_export.h"
#include <wiretap/wtap.h>
+#include <capture_info.h>
#ifdef __cplusplus
extern "C" {
@@ -46,6 +47,9 @@ WS_DLL_PUBLIC void register_capture_dissector(const char* name, const guint32 pa
WS_DLL_PUBLIC gboolean try_capture_dissector(const char* name, const guint32 pattern, const guchar *pd, int offset, int len, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header);
+WS_DLL_PUBLIC guint32 capture_dissector_get_count(packet_counts* counts, const int proto);
+WS_DLL_PUBLIC void capture_dissector_increment_count(capture_packet_info_t *cpinfo, const int proto);
+
extern void capture_dissector_init(void);
extern void capture_dissector_cleanup(void);
diff --git a/epan/dissectors/packet-arcnet.c b/epan/dissectors/packet-arcnet.c
index ab10565bc2..3c60c40b62 100644
--- a/epan/dissectors/packet-arcnet.c
+++ b/epan/dissectors/packet-arcnet.c
@@ -54,6 +54,9 @@ static int arcnet_address_type = -1;
static dissector_table_t arcnet_dissector_table;
static dissector_handle_t data_handle;
+/* Cache protocol for packet counting */
+static int proto_ipx = -1;
+
static int arcnet_str_len(const address* addr _U_)
{
return 5;
@@ -143,7 +146,7 @@ capture_arcnet_common(const guchar *pd, int offset, int len, capture_packet_info
return capture_arp(pd, offset + 1, len, cpinfo, pseudo_header);
case ARCNET_PROTO_IPX:
- cpinfo->counts->ipx++;
+ capture_dissector_increment_count(cpinfo, proto_ipx);
break;
default:
@@ -408,6 +411,8 @@ proto_reg_handoff_arcnet (void)
arcnet_linux_handle = create_dissector_handle (dissect_arcnet_linux, proto_arcnet);
dissector_add_uint ("wtap_encap", WTAP_ENCAP_ARCNET_LINUX, arcnet_linux_handle);
+ proto_ipx = proto_get_id_by_filter_name("ipx");
+
register_capture_dissector("wtap_encap", WTAP_ENCAP_ARCNET_LINUX, capture_arcnet, proto_arcnet);
register_capture_dissector("wtap_encap", WTAP_ENCAP_ARCNET, capture_arcnet_has_exception, proto_arcnet);
data_handle = find_dissector ("data");
diff --git a/epan/dissectors/packet-arp.c b/epan/dissectors/packet-arp.c
index beff539f2f..d171f00a7a 100644
--- a/epan/dissectors/packet-arp.c
+++ b/epan/dissectors/packet-arp.c
@@ -1362,7 +1362,7 @@ dissect_ax25arp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data
gboolean
capture_arp(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header _U_)
{
- cpinfo->counts->arp++;
+ capture_dissector_increment_count(cpinfo, proto_arp);
return TRUE;
}
diff --git a/epan/dissectors/packet-gre.c b/epan/dissectors/packet-gre.c
index 7e17ea2ce8..03de868d18 100644
--- a/epan/dissectors/packet-gre.c
+++ b/epan/dissectors/packet-gre.c
@@ -314,7 +314,7 @@ dissect_gre_wccp2_redirect_header(tvbuff_t *tvb, int offset, proto_tree *tree)
static gboolean
capture_gre(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header _U_)
{
- cpinfo->counts->gre++;
+ capture_dissector_increment_count(cpinfo, proto_gre);
return TRUE;
}
diff --git a/epan/dissectors/packet-i2c.c b/epan/dissectors/packet-i2c.c
index 78a1525298..5b5cc4a5d5 100644
--- a/epan/dissectors/packet-i2c.c
+++ b/epan/dissectors/packet-i2c.c
@@ -34,6 +34,9 @@ void proto_register_i2c(void);
void proto_reg_handoff_i2c(void);
static int proto_i2c = -1;
+static int proto_i2c_event = -1;
+static int proto_i2c_data = -1;
+
static int hf_i2c_bus = -1;
static int hf_i2c_event = -1;
@@ -88,9 +91,9 @@ static gboolean
capture_i2c(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header)
{
if (pseudo_header->i2c.is_event) {
- cpinfo->counts->i2c_event++;
+ capture_dissector_increment_count(cpinfo, proto_i2c_event);
} else {
- cpinfo->counts->i2c_data++;
+ capture_dissector_increment_count(cpinfo, proto_i2c_data);
}
return TRUE;
@@ -245,6 +248,10 @@ proto_register_i2c(void)
static decode_as_t i2c_da = {"i2c", "I2C Message", "i2c.message", 1, 0, &i2c_da_values, NULL, NULL,
decode_as_default_populate_list, decode_as_default_reset, decode_as_default_change, NULL};
+ /* Placeholders for capture statistics */
+ proto_i2c_event = proto_register_protocol("I2C Events", "I2C Events", "i2c_event");
+ proto_i2c_data = proto_register_protocol("I2C Data", "I2C Data", "i2c_data");
+
proto_i2c = proto_register_protocol("Inter-Integrated Circuit", "I2C", "i2c");
proto_register_field_array(proto_i2c, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
diff --git a/epan/dissectors/packet-icmp.c b/epan/dissectors/packet-icmp.c
index ae31bbdde3..a858201f90 100644
--- a/epan/dissectors/packet-icmp.c
+++ b/epan/dissectors/packet-icmp.c
@@ -1167,7 +1167,7 @@ get_best_guess_mstimeofday(tvbuff_t * tvb, gint offset, guint32 comp_ts)
static gboolean
capture_icmp(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header _U_)
{
- cpinfo->counts->icmp++;
+ capture_dissector_increment_count(cpinfo, proto_icmp);
return TRUE;
}
diff --git a/epan/dissectors/packet-icmpv6.c b/epan/dissectors/packet-icmpv6.c
index ded2043bac..69b4e6cac7 100644
--- a/epan/dissectors/packet-icmpv6.c
+++ b/epan/dissectors/packet-icmpv6.c
@@ -3454,7 +3454,7 @@ dissect_mldrv2( tvbuff_t *tvb, guint32 offset, packet_info *pinfo _U_, proto_tre
static gboolean
capture_icmpv6(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header _U_)
{
- cpinfo->counts->icmp++;
+ capture_dissector_increment_count(cpinfo, proto_icmpv6);
return TRUE;
}
diff --git a/epan/dissectors/packet-ip.c b/epan/dissectors/packet-ip.c
index 7f6b7c3807..55b974361f 100644
--- a/epan/dissectors/packet-ip.c
+++ b/epan/dissectors/packet-ip.c
@@ -572,6 +572,7 @@ capture_ip(const guchar *pd, int offset, int len, capture_packet_info_t *cpinfo,
if (!BYTES_ARE_IN_FRAME(offset, len, IPH_MIN_LEN))
return FALSE;
+ capture_dissector_increment_count(cpinfo, proto_ip);
return try_capture_dissector("ip.proto", pd[offset + 9], pd, offset+IPH_MIN_LEN, len, cpinfo, pseudo_header);
}
diff --git a/epan/dissectors/packet-ipv6.c b/epan/dissectors/packet-ipv6.c
index b6ce19979d..b6d0cb2539 100644
--- a/epan/dissectors/packet-ipv6.c
+++ b/epan/dissectors/packet-ipv6.c
@@ -530,6 +530,8 @@ capture_ipv6(const guchar *pd, int offset, int len, capture_packet_info_t *cpinf
if (!BYTES_ARE_IN_FRAME(offset, len, 4+4+16+16))
return FALSE;
+ capture_dissector_increment_count(cpinfo, proto_ipv6);
+
nxt = pd[offset+6]; /* get the "next header" value */
offset += 4+4+16+16; /* skip past the IPv6 header */
diff --git a/epan/dissectors/packet-ipx.c b/epan/dissectors/packet-ipx.c
index dff60bc75a..4cdf987fcb 100644
--- a/epan/dissectors/packet-ipx.c
+++ b/epan/dissectors/packet-ipx.c
@@ -276,7 +276,7 @@ static const value_string ipxmsg_sigchar_vals[] = {
gboolean
capture_ipx(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header _U_)
{
- cpinfo->counts->ipx++;
+ capture_dissector_increment_count(cpinfo, proto_ipx);
return TRUE;
}
diff --git a/epan/dissectors/packet-netbios.c b/epan/dissectors/packet-netbios.c
index 6a3811bf3a..62b06b4d24 100644
--- a/epan/dissectors/packet-netbios.c
+++ b/epan/dissectors/packet-netbios.c
@@ -32,6 +32,7 @@
#include <epan/reassemble.h>
#include <epan/prefs.h>
#include <epan/expert.h>
+#include <epan/capture_dissectors.h>
#include "packet-netbios.h"
void proto_register_netbios(void);
@@ -288,7 +289,7 @@ static const value_string max_frame_size_vals[] = {
static gboolean
capture_netbios(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header _U_)
{
- cpinfo->counts->netbios++;
+ capture_dissector_increment_count(cpinfo, proto_netbios);
return TRUE;
}
diff --git a/epan/dissectors/packet-ospf.c b/epan/dissectors/packet-ospf.c
index 4f904466be..167bb9d83d 100644
--- a/epan/dissectors/packet-ospf.c
+++ b/epan/dissectors/packet-ospf.c
@@ -1043,7 +1043,7 @@ ospf_has_at_block(tvbuff_t *tvb, int offset, guint8 packet_type, guint8 version)
static gboolean
capture_ospf(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header _U_)
{
- cpinfo->counts->ospf++;
+ capture_dissector_increment_count(cpinfo, proto_ospf);
return TRUE;
}
diff --git a/epan/dissectors/packet-sctp.c b/epan/dissectors/packet-sctp.c
index 42948149ea..e7519d3401 100644
--- a/epan/dissectors/packet-sctp.c
+++ b/epan/dissectors/packet-sctp.c
@@ -4688,7 +4688,7 @@ dissect_sctp_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboolea
static gboolean
capture_sctp(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header _U_)
{
- cpinfo->counts->sctp++;
+ capture_dissector_increment_count(cpinfo, proto_sctp);
return TRUE;
}
diff --git a/epan/dissectors/packet-tcp.c b/epan/dissectors/packet-tcp.c
index 9771f8d5c0..6f4dca0882 100644
--- a/epan/dissectors/packet-tcp.c
+++ b/epan/dissectors/packet-tcp.c
@@ -4807,7 +4807,7 @@ capture_tcp(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_in
if (!BYTES_ARE_IN_FRAME(offset, len, 4))
return FALSE;
- cpinfo->counts->tcp++;
+ capture_dissector_increment_count(cpinfo, proto_tcp);
src_port = pntoh16(&pd[offset]);
dst_port = pntoh16(&pd[offset+2]);
diff --git a/epan/dissectors/packet-udp.c b/epan/dissectors/packet-udp.c
index 1e784a4a3a..4a1a6dbabe 100644
--- a/epan/dissectors/packet-udp.c
+++ b/epan/dissectors/packet-udp.c
@@ -699,7 +699,7 @@ capture_udp(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_in
if (!BYTES_ARE_IN_FRAME(offset, len, 4))
return FALSE;
- cpinfo->counts->udp++;
+ capture_dissector_increment_count(cpinfo, hfi_udp->id);
src_port = pntoh16(&pd[offset]);
dst_port = pntoh16(&pd[offset+2]);
diff --git a/epan/dissectors/packet-vines.c b/epan/dissectors/packet-vines.c
index 7cafb52b2c..b7f523fb73 100644
--- a/epan/dissectors/packet-vines.c
+++ b/epan/dissectors/packet-vines.c
@@ -256,6 +256,7 @@ static gint ett_vines_rtp_control_flags = -1;
static gint ett_vines_rtp_mtype = -1;
static gint ett_vines_rtp_flags = -1;
+static int proto_vines = -1;
static int proto_vines_icp = -1;
static int hf_vines_icp_exception_code = -1;
static int hf_vines_icp_metric = -1;
@@ -311,7 +312,7 @@ typedef struct _e_vipc {
gboolean
capture_vines(const guchar *pd _U_, int offset _U_, int len _U_, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header _U_)
{
- cpinfo->counts->vines++;
+ capture_dissector_increment_count(cpinfo, proto_vines);
return TRUE;
}
@@ -2004,6 +2005,8 @@ proto_register_vines_icp(void)
proto_vines_icp = proto_register_protocol(
"Banyan Vines ICP", "Vines ICP", "vines_icp");
+ /* Placeholder for capture statistics */
+ proto_vines = proto_register_protocol("VINES", "VINES", "vines");
proto_register_field_array(proto_vines_icp, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
}
diff --git a/epan/packet.h b/epan/packet.h
index 9690238949..cc13140bf6 100644
--- a/epan/packet.h
+++ b/epan/packet.h
@@ -56,33 +56,8 @@ struct epan_range;
((guint)(offset) + (guint)(len) > (guint)(offset) && \
(guint)(offset) + (guint)(len) <= (guint)(captured_len))
-/*
- * GTK+ only.
- * If we add this to the Qt UI we should modernize the statistics we show.
- * At the very least we should remove or hide IPX and VINES.
- */
-typedef struct _packet_counts {
- gint sctp;
- gint tcp;
- gint udp;
- gint icmp;
- gint ospf;
- gint gre;
- gint netbios;
- gint ipx;
- gint vines;
- gint other;
- gint total;
- gint arp;
- gint i2c_event;
- gint i2c_data;
-} packet_counts;
-
-/** Number of packet counts. */
-#define PACKET_COUNTS_SIZE sizeof(packet_counts) / sizeof (gint)
-
typedef struct _capture_packet_info {
- packet_counts *counts;
+ GHashTable *counts;
} capture_packet_info_t;
extern void packet_init(void);
diff --git a/ui/gtk/capture_info_dlg.c b/ui/gtk/capture_info_dlg.c
index a3b392c0c8..d78eee51bf 100644
--- a/ui/gtk/capture_info_dlg.c
+++ b/ui/gtk/capture_info_dlg.c
@@ -29,6 +29,7 @@
#include <gtk/gtk.h>
#include <epan/packet.h>
+#include <epan/capture_dissectors.h>
#include "ui/capture.h"
#include "../capture_info.h"
@@ -54,14 +55,19 @@
/* corresponding value packet_counts, to speed up (and simplify) output of values */
typedef struct {
const gchar *title;
- gint *value_ptr;
+ int proto;
GtkWidget *label, *value_lb, *percent_pb, *percent_lb;
} capture_info_counts_t;
+/** Number of packet counts. */
+#define PACKET_COUNTS_SIZE 12
+
/* all data we need to know of this dialog, after creation finished */
typedef struct {
GtkWidget *cap_w;
GtkWidget *running_time_lb;
+ capture_info_counts_t total_count;
+ capture_info_counts_t other_count;
capture_info_counts_t counts[PACKET_COUNTS_SIZE];
guint timer_id;
time_t start_time;
@@ -105,6 +111,45 @@ capture_info_ui_update_cb(gpointer data)
return TRUE; /* call the timer again */
}
+static void
+capture_info_count_init(capture_info_counts_t* count, int idx, GtkWidget *percent_pb, gboolean show, GtkWidget *counts_grid)
+{
+ count->label = gtk_label_new(count->title);
+ gtk_misc_set_alignment(GTK_MISC(count->label), 0.0f, 0.5f);
+
+ count->value_lb = gtk_label_new("0");
+ gtk_misc_set_alignment(GTK_MISC(count->value_lb), 0.5f, 0.5f);
+
+ count->percent_pb = percent_pb;
+
+ if (!show) /* Do for all but "total" */
+ {
+ /* downsize the default size of this progress bar in x direction (def:150), */
+ /* otherwise it will become too large and the dialog will look ugly */
+ /* XXX: use a TreeView instead of a grid in order to fix this */
+ gtk_widget_set_size_request(count->percent_pb, 70, -1);
+ }
+
+ count->percent_lb = gtk_label_new("0.0%");
+ gtk_misc_set_alignment(GTK_MISC(count->percent_lb), 1.0f, 0.5f);
+
+ ws_gtk_grid_attach_extended(GTK_GRID(counts_grid), count->label,
+ 0, idx, 1, 1, (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0, 0);
+ ws_gtk_grid_attach_extended(GTK_GRID(counts_grid), count->value_lb,
+ 1, idx, 1, 1, (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0, 0);
+ ws_gtk_grid_attach_extended(GTK_GRID(counts_grid), count->percent_pb,
+ 2, idx, 1, 1, (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0, 0);
+ ws_gtk_grid_attach_extended(GTK_GRID(counts_grid), count->percent_lb,
+ 3, idx, 1, 1, (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0, 0);
+
+ gtk_widget_show(count->label);
+ gtk_widget_show(count->value_lb);
+ gtk_widget_show(count->percent_pb);
+ /* don't show percentages for the "total" row */
+ if (show) {
+ gtk_widget_show(count->percent_lb);
+ }
+}
/* create the capture info dialog */
/* will keep pointers to the fields in the counts parameter */
@@ -121,34 +166,33 @@ capture_info_ui_create(capture_info *cinfo, capture_session *cap_session)
GString *str;
info = g_new0(capture_info_ui_t,1);
- info->counts[0].title = "Total";
- info->counts[0].value_ptr = &(cinfo->counts->total);
- info->counts[1].title = "SCTP";
- info->counts[1].value_ptr = &(cinfo->counts->sctp);
- info->counts[2].title = "TCP";
- info->counts[2].value_ptr = &(cinfo->counts->tcp);
- info->counts[3].title = "UDP";
- info->counts[3].value_ptr = &(cinfo->counts->udp);
- info->counts[4].title = "ICMP";
- info->counts[4].value_ptr = &(cinfo->counts->icmp);
- info->counts[5].title = "ARP";
- info->counts[5].value_ptr = &(cinfo->counts->arp);
- info->counts[6].title = "OSPF";
- info->counts[6].value_ptr = &(cinfo->counts->ospf);
- info->counts[7].title = "GRE";
- info->counts[7].value_ptr = &(cinfo->counts->gre);
- info->counts[8].title = "NetBIOS";
- info->counts[8].value_ptr = &(cinfo->counts->netbios);
- info->counts[9].title = "IPX";
- info->counts[9].value_ptr = &(cinfo->counts->ipx);
- info->counts[10].title = "VINES";
- info->counts[10].value_ptr = &(cinfo->counts->vines);
- info->counts[11].title = "Other";
- info->counts[11].value_ptr = &(cinfo->counts->other);
- info->counts[12].title = "I2C Events";
- info->counts[12].value_ptr = &(cinfo->counts->i2c_event);
- info->counts[13].title = "I2C Data";
- info->counts[13].value_ptr = &(cinfo->counts->i2c_data);
+ info->total_count.title = "Total";
+ info->other_count.title = "Other";
+
+ info->counts[0].title = "SCTP";
+ info->counts[0].proto = proto_get_id_by_short_name(info->counts[0].title);
+ info->counts[1].title = "TCP";
+ info->counts[1].proto = proto_get_id_by_short_name(info->counts[1].title);
+ info->counts[2].title = "UDP";
+ info->counts[2].proto = proto_get_id_by_short_name(info->counts[2].title);
+ info->counts[3].title = "ICMP";
+ info->counts[3].proto = proto_get_id_by_short_name(info->counts[3].title);
+ info->counts[4].title = "ARP";
+ info->counts[4].proto = proto_get_id_by_short_name(info->counts[4].title);
+ info->counts[5].title = "OSPF";
+ info->counts[5].proto = proto_get_id_by_short_name(info->counts[5].title);
+ info->counts[6].title = "GRE";
+ info->counts[6].proto = proto_get_id_by_short_name(info->counts[6].title);
+ info->counts[7].title = "NetBIOS";
+ info->counts[7].proto = proto_get_id_by_short_name(info->counts[7].title);
+ info->counts[8].title = "IPX";
+ info->counts[8].proto = proto_get_id_by_short_name(info->counts[8].title);
+ info->counts[9].title = "VINES";
+ info->counts[9].proto = proto_get_id_by_short_name(info->counts[9].title);
+ info->counts[10].title = "I2C Events";
+ info->counts[10].proto = proto_get_id_by_short_name(info->counts[10].title);
+ info->counts[11].title = "I2C Data";
+ info->counts[11].proto = proto_get_id_by_short_name(info->counts[11].title);
/*
* Create the dialog window, with a title that includes the interfaces
@@ -182,49 +226,14 @@ capture_info_ui_create(capture_info *cinfo, capture_session *cap_session)
ws_gtk_grid_set_row_spacing(GTK_GRID(counts_grid), 0);
ws_gtk_grid_set_column_spacing(GTK_GRID(counts_grid), 5);
- for (i = 0; i < PACKET_COUNTS_SIZE; i++) {
- info->counts[i].label = gtk_label_new(info->counts[i].title);
- gtk_misc_set_alignment(GTK_MISC(info->counts[i].label), 0.0f, 0.5f);
-
- info->counts[i].value_lb = gtk_label_new("0");
- gtk_misc_set_alignment(GTK_MISC(info->counts[i].value_lb), 0.5f, 0.5f);
-
- if (i == 0) {
- /* do not build a progress bar for the "total" row */
- /* (as this could suggest a "buffer full" to the user) */
- /* simply put a label here */
- info->counts[i].percent_pb = gtk_label_new("% of total");
- } else {
- /* build a progress bar in the other rows */
- info->counts[i].percent_pb = gtk_progress_bar_new();
-
- /* downsize the default size of this progress bar in x direction (def:150), */
- /* otherwise it will become too large and the dialog will look ugly */
- /* XXX: use a TreeView instead of a grid in order to fix this */
- gtk_widget_set_size_request(info->counts[i].percent_pb, 70, -1);
- }
+ capture_info_count_init(&info->total_count, 0, gtk_label_new("% of total"), FALSE, counts_grid);
- info->counts[i].percent_lb = gtk_label_new("0.0%");
- gtk_misc_set_alignment(GTK_MISC(info->counts[i].percent_lb), 1.0f, 0.5f);
-
- ws_gtk_grid_attach_extended(GTK_GRID(counts_grid), info->counts[i].label,
- 0, i, 1, 1, (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0, 0);
- ws_gtk_grid_attach_extended(GTK_GRID(counts_grid), info->counts[i].value_lb,
- 1, i, 1, 1, (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0, 0);
- ws_gtk_grid_attach_extended(GTK_GRID(counts_grid), info->counts[i].percent_pb,
- 2, i, 1, 1, (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0, 0);
- ws_gtk_grid_attach_extended(GTK_GRID(counts_grid), info->counts[i].percent_lb,
- 3, i, 1, 1, (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0, 0);
-
- gtk_widget_show(info->counts[i].label);
- gtk_widget_show(info->counts[i].value_lb);
- gtk_widget_show(info->counts[i].percent_pb);
- /* don't show percentages for the "total" row */
- if (i != 0) {
- gtk_widget_show(info->counts[i].percent_lb);
- }
+ for (i = 0; i < PACKET_COUNTS_SIZE; i++) {
+ capture_info_count_init(&info->counts[i], i+1, gtk_progress_bar_new(), TRUE, counts_grid);
}
+ capture_info_count_init(&info->other_count, i+1, gtk_progress_bar_new(), TRUE, counts_grid);
+
/* Running time */
running_grid = ws_gtk_grid_new();
ws_gtk_grid_set_homogeneous(GTK_GRID(running_grid), TRUE);
@@ -280,6 +289,26 @@ capture_info_ui_create(capture_info *cinfo, capture_session *cap_session)
info->timer_id = g_timeout_add(1000, capture_info_ui_update_cb,cinfo);
}
+static void
+capture_info_count_update(capture_info_counts_t* count, capture_info *cinfo)
+{
+ gchar label_str[64];
+ float pb_frac;
+ guint32 proto_count;
+
+ proto_count = capture_dissector_get_count(cinfo->counts, count->proto);
+
+ g_snprintf(label_str, sizeof(label_str), "%d", proto_count);
+ gtk_label_set_text(GTK_LABEL(count->value_lb), label_str);
+
+ pb_frac = (cinfo->counts->total != 0) ?
+ ((float)proto_count / cinfo->counts->total) : 0.0f;
+
+ /* don't try to update the "total" row progress bar */
+ gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(count->percent_pb), pb_frac);
+ g_snprintf(label_str, sizeof(label_str), "%.1f%%", pb_frac * 100.0);
+ gtk_label_set_text(GTK_LABEL(count->percent_lb), label_str);
+}
/* update the capture info dialog */
/* As this function is a bit time critical while capturing, */
@@ -303,20 +332,25 @@ capture_info *cinfo)
/* if we have new packets, update all rows */
if (cinfo->new_packets) {
float pb_frac;
+
+ /* First setup total */
+ g_snprintf(label_str, sizeof(label_str), "%d", cinfo->counts->total);
+ gtk_label_set_text(GTK_LABEL(info->total_count.value_lb), label_str);
+
for (i = 0; i < PACKET_COUNTS_SIZE; i++) {
- g_snprintf(label_str, sizeof(label_str), "%d", *info->counts[i].value_ptr);
- gtk_label_set_text(GTK_LABEL(info->counts[i].value_lb), label_str);
-
- pb_frac = (*info->counts[0].value_ptr != 0) ?
- ((float)*info->counts[i].value_ptr / *info->counts[0].value_ptr) : 0.0f;
-
- /* don't try to update the "total" row progress bar */
- if (i != 0) {
- gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(info->counts[i].percent_pb), pb_frac);
- g_snprintf(label_str, sizeof(label_str), "%.1f%%", pb_frac * 100.0);
- gtk_label_set_text(GTK_LABEL(info->counts[i].percent_lb), label_str);
- }
+ capture_info_count_update(&info->counts[i], cinfo);
}
+
+ /* Now handle "other" packets */
+ g_snprintf(label_str, sizeof(label_str), "%d", cinfo->counts->other);
+ gtk_label_set_text(GTK_LABEL(info->other_count.value_lb), label_str);
+
+ pb_frac = (cinfo->counts->total != 0) ?
+ ((float)cinfo->counts->other / cinfo->counts->total) : 0.0f;
+
+ gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(info->other_count.percent_pb), pb_frac);
+ g_snprintf(label_str, sizeof(label_str), "%.1f%%", pb_frac * 100.0);
+ gtk_label_set_text(GTK_LABEL(info->other_count.percent_lb), label_str);
}
}