summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2015-12-16 23:15:03 -0500
committerMichael Mann <mmann78@netscape.net>2015-12-19 14:22:56 +0000
commit444dfda793784cecda0757cbe50e27a5ba855ba0 (patch)
treeec34e5780c2dbe29bc2f170c2fc406ee20aa0430
parent7baac67149a68b66087c5d688dbeda2869485765 (diff)
downloadwireshark-444dfda793784cecda0757cbe50e27a5ba855ba0.tar.gz
Allow "capture info data" to not be a singleton.
It was buried as a static variable in capture_info.c, and functions were refactored to allow a pointer to the info_data_t structure to be passed in. TShark and GTK will have their own single (global) copy of the structure, while it opens up Qt to have multiple instances. Change-Id: Ic2d7a2ad574de43f457cb18b194d6bc3fffb6120 Reviewed-on: https://code.wireshark.org/review/12691 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
-rw-r--r--capchild/capture_session.h3
-rw-r--r--capchild/capture_sync.c3
-rw-r--r--capchild/capture_sync.h4
-rw-r--r--capture_info.c88
-rw-r--r--capture_info.h34
-rw-r--r--tshark.c4
-rw-r--r--ui/capture.c14
-rw-r--r--ui/capture.h3
-rw-r--r--ui/capture_globals.h4
-rw-r--r--ui/gtk/capture_dlg.c2
-rw-r--r--ui/gtk/gtkglobals.h7
-rw-r--r--ui/gtk/main.c5
-rw-r--r--ui/qt/main_window.h2
-rw-r--r--ui/qt/main_window_slots.cpp2
-rw-r--r--wireshark-qt.cpp2
15 files changed, 92 insertions, 85 deletions
diff --git a/capchild/capture_session.h b/capchild/capture_session.h
index d55ef1f768..e10eeb5f7b 100644
--- a/capchild/capture_session.h
+++ b/capchild/capture_session.h
@@ -45,7 +45,7 @@ typedef enum {
} capture_state;
struct _capture_file;
-
+struct _info_data;
/*
* State of a capture session.
*/
@@ -64,6 +64,7 @@ typedef struct _capture_session {
guint32 count; /**< Total number of frames captured */
capture_options *capture_opts; /**< options for this capture */
struct _capture_file *cf; /**< handle to cfile */
+ struct _info_data *cap_data_info; /**< stats for this capture */
} capture_session;
extern void
diff --git a/capchild/capture_sync.c b/capchild/capture_sync.c
index a698efc5e0..6f02219d60 100644
--- a/capchild/capture_sync.c
+++ b/capchild/capture_sync.c
@@ -339,7 +339,7 @@ init_pipe_args(int *argc) {
#define ARGV_NUMBER_LEN 24
/* a new capture run: start a new dumpcap task and hand over parameters through command line */
gboolean
-sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, void (*update_cb)(void))
+sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, info_data_t* cap_data, void (*update_cb)(void))
{
char ssnap[ARGV_NUMBER_LEN];
char scount[ARGV_NUMBER_LEN];
@@ -772,6 +772,7 @@ sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, voi
cap_session->fork_child_status = 0;
cap_session->capture_opts = capture_opts;
+ cap_session->cap_data_info = cap_data;
/* we might wait for a moment till child is ready, so update screen now */
if (update_cb) update_cb();
diff --git a/capchild/capture_sync.h b/capchild/capture_sync.h
index 3cdac27956..2f4a512af0 100644
--- a/capchild/capture_sync.h
+++ b/capchild/capture_sync.h
@@ -36,6 +36,8 @@
extern "C" {
#endif /* __cplusplus */
+struct _info_data;
+
/**
* Start a new capture session.
* Create a capture child which is doing the real capture work.
@@ -50,7 +52,7 @@ extern "C" {
* @return TRUE if a capture could be started, FALSE if not
*/
extern gboolean
-sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, void(*update_cb)(void));
+sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, struct _info_data* cap_data, void(*update_cb)(void));
/** User wants to stop capturing, gracefully close the capture child */
extern void
diff --git a/capture_info.c b/capture_info.c
index 171a1e2f90..3eafb10bf1 100644
--- a/capture_info.c
+++ b/capture_info.c
@@ -27,10 +27,6 @@
#include <glib.h>
#include <epan/packet.h>
-/* XXX - try to remove this later */
-#include <epan/prefs.h>
-/* XXX - try to remove this later */
-
#include <wiretap/wtap.h>
#include "capture_info.h"
@@ -39,38 +35,28 @@
#include <wsutil/filesystem.h>
-typedef struct _info_data {
- packet_counts counts; /* several packet type counters */
- struct wtap* wtap; /* current wtap file */
- capture_info ui; /* user interface data */
-} info_data_t;
-
-
-static info_data_t info_data;
-
-
/* open the info */
-void capture_info_open(capture_session *cap_session)
+void capture_info_open(capture_session *cap_session, info_data_t* cap_info)
{
- info_data.counts.total = 0;
- info_data.counts.sctp = 0;
- info_data.counts.tcp = 0;
- info_data.counts.udp = 0;
- info_data.counts.icmp = 0;
- info_data.counts.ospf = 0;
- info_data.counts.gre = 0;
- info_data.counts.ipx = 0;
- info_data.counts.netbios = 0;
- info_data.counts.vines = 0;
- info_data.counts.other = 0;
- info_data.counts.arp = 0;
- info_data.counts.i2c_event = 0;
- info_data.counts.i2c_data = 0;
-
- info_data.wtap = NULL;
- info_data.ui.counts = &info_data.counts;
-
- capture_info_ui_create(&info_data.ui, cap_session);
+ 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;
+
+ cap_info->wtap = NULL;
+ cap_info->ui.counts = &cap_info->counts;
+
+ capture_info_ui_create(&cap_info->ui, cap_session);
}
@@ -175,19 +161,19 @@ cf_open_error_message(int err, gchar *err_info, gboolean for_writing,
}
/* new file arrived */
-gboolean capture_info_new_file(const char *new_filename)
+gboolean capture_info_new_file(const char *new_filename, info_data_t* cap_info)
{
int err;
gchar *err_info;
gchar *err_msg;
- if(info_data.wtap != NULL) {
- wtap_close(info_data.wtap);
+ if(cap_info->wtap != NULL) {
+ wtap_close(cap_info->wtap);
}
- info_data.wtap = wtap_open_offline(new_filename, WTAP_TYPE_AUTO, &err, &err_info, FALSE);
- if (!info_data.wtap) {
+ cap_info->wtap = wtap_open_offline(new_filename, WTAP_TYPE_AUTO, &err, &err_info, FALSE);
+ if (!cap_info->wtap) {
err_msg = g_strdup_printf(cf_open_error_message(err, err_info, FALSE, WTAP_FILE_TYPE_SUBTYPE_UNKNOWN),
new_filename);
g_warning("capture_info_new_file: %d (%s)", err, err_msg);
@@ -211,7 +197,7 @@ capture_info_packet(packet_counts *counts, gint wtap_linktype, const guchar *pd,
}
/* new packets arrived */
-void capture_info_new_packets(int to_read)
+void capture_info_new_packets(int to_read, info_data_t* cap_info)
{
int err;
gchar *err_info;
@@ -222,35 +208,35 @@ void capture_info_new_packets(int to_read)
const guchar *buf;
- info_data.ui.new_packets = to_read;
+ cap_info->ui.new_packets = to_read;
/*g_warning("new packets: %u", to_read);*/
while (to_read > 0) {
- wtap_cleareof(info_data.wtap);
- if (wtap_read(info_data.wtap, &err, &err_info, &data_offset)) {
- phdr = wtap_phdr(info_data.wtap);
+ wtap_cleareof(cap_info->wtap);
+ if (wtap_read(cap_info->wtap, &err, &err_info, &data_offset)) {
+ phdr = wtap_phdr(cap_info->wtap);
pseudo_header = &phdr->pseudo_header;
wtap_linktype = phdr->pkt_encap;
- buf = wtap_buf_ptr(info_data.wtap);
+ buf = wtap_buf_ptr(cap_info->wtap);
- capture_info_packet(&info_data.counts, wtap_linktype, buf, phdr->caplen, pseudo_header);
+ capture_info_packet(&cap_info->counts, wtap_linktype, buf, phdr->caplen, pseudo_header);
/*g_warning("new packet");*/
to_read--;
}
}
- capture_info_ui_update(&info_data.ui);
+ capture_info_ui_update(&cap_info->ui);
}
/* close the info */
-void capture_info_close(void)
+void capture_info_close(info_data_t* cap_info)
{
- capture_info_ui_destroy(&info_data.ui);
- if(info_data.wtap)
- wtap_close(info_data.wtap);
+ capture_info_ui_destroy(&cap_info->ui);
+ if(cap_info->wtap)
+ wtap_close(cap_info->wtap);
}
#endif /* HAVE_LIBPCAP */
diff --git a/capture_info.h b/capture_info.h
index 8a72114a8f..abc0b2e91f 100644
--- a/capture_info.h
+++ b/capture_info.h
@@ -39,24 +39,13 @@
#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 */
-/* open the info - init values (wtap, counts), create dialog */
-extern void capture_info_open(capture_session *cap_session);
-
-/* new file arrived - (eventually close old wtap), open wtap */
-extern gboolean capture_info_new_file(const char *new_filename);
-
-/* new packets arrived - read from wtap, count */
-extern void capture_info_new_packets(int to_read);
-
-/* close the info - close wtap, destroy dialog */
-extern void capture_info_close(void);
-
-
-
/** Current Capture info. */
typedef struct {
/* handle */
@@ -68,6 +57,23 @@ typedef struct {
gint new_packets; /**< packets since last update */
} capture_info;
+typedef struct _info_data {
+ packet_counts counts; /* several packet type counters */
+ struct wtap* wtap; /* current wtap file */
+ capture_info ui; /* user interface data */
+} info_data_t;
+
+/* open the info - init values (wtap, counts), create dialog */
+extern void capture_info_open(capture_session *cap_session, info_data_t* cap_info);
+
+/* new file arrived - (eventually close old wtap), open wtap */
+extern gboolean capture_info_new_file(const char *new_filename, info_data_t* cap_info);
+
+/* new packets arrived - read from wtap, count */
+extern void capture_info_new_packets(int to_read, info_data_t* cap_info);
+
+/* close the info - close wtap, destroy dialog */
+extern void capture_info_close(info_data_t* cap_info);
/** Create the capture info dialog */
extern void
diff --git a/tshark.c b/tshark.c
index 10b9ecf8df..c5d4fb6ffc 100644
--- a/tshark.c
+++ b/tshark.c
@@ -113,6 +113,7 @@
#endif /* _WIN32 */
#include <capchild/capture_session.h>
#include <capchild/capture_sync.h>
+#include <capture_info.h>
#endif /* HAVE_LIBPCAP */
#include "log.h"
#include <epan/funnel.h>
@@ -184,6 +185,7 @@ static gboolean print_packet_counts;
static capture_options global_capture_opts;
static capture_session global_capture_session;
+static info_data_t global_info_data;
#ifdef SIGINFO
static gboolean infodelay; /* if TRUE, don't print capture info in SIGINFO handler */
@@ -2562,7 +2564,7 @@ capture(void)
fflush(stderr);
g_string_free(str, TRUE);
- ret = sync_pipe_start(&global_capture_opts, &global_capture_session, NULL);
+ ret = sync_pipe_start(&global_capture_opts, &global_capture_session, &global_info_data, NULL);
if (!ret)
return FALSE;
diff --git a/ui/capture.c b/ui/capture.c
index 0a95cf8be9..f3818a6ef8 100644
--- a/ui/capture.c
+++ b/ui/capture.c
@@ -126,7 +126,7 @@ capture_callback_remove(capture_callback_t func, gpointer user_data)
* @return TRUE if the capture starts successfully, FALSE otherwise.
*/
gboolean
-capture_start(capture_options *capture_opts, capture_session *cap_session, void(*update_cb)(void))
+capture_start(capture_options *capture_opts, capture_session *cap_session, info_data_t* cap_data, void(*update_cb)(void))
{
gboolean ret;
GString *source;
@@ -138,7 +138,7 @@ capture_start(capture_options *capture_opts, capture_session *cap_session, void(
cf_set_tempfile_source((capture_file *)cap_session->cf, source->str);
g_string_free(source, TRUE);
/* try to start the capture child process */
- ret = sync_pipe_start(capture_opts, cap_session, update_cb);
+ ret = sync_pipe_start(capture_opts, cap_session, cap_data, update_cb);
if(!ret) {
if(capture_opts->save_file != NULL) {
g_free(capture_opts->save_file);
@@ -156,7 +156,7 @@ capture_start(capture_options *capture_opts, capture_session *cap_session, void(
capture_callback_invoke(capture_cb_capture_prepared, cap_session);
if(capture_opts->show_info)
- capture_info_open(cap_session);
+ capture_info_open(cap_session, cap_data);
}
return ret;
@@ -346,7 +346,7 @@ capture_input_new_file(capture_session *cap_session, gchar *new_file)
}
if(capture_opts->show_info) {
- if (!capture_info_new_file(new_file))
+ if (!capture_info_new_file(new_file, cap_session->cap_data_info))
return FALSE;
}
@@ -403,7 +403,7 @@ capture_input_new_packets(capture_session *cap_session, int to_read)
#endif
if(capture_opts->show_info)
- capture_info_new_packets(to_read);
+ capture_info_new_packets(to_read, cap_session->cap_data_info);
}
@@ -594,7 +594,7 @@ capture_input_closed(capture_session *cap_session, gchar *msg)
}
if(capture_opts->show_info)
- capture_info_close();
+ capture_info_close(cap_session->cap_data_info);
cap_session->state = CAPTURE_STOPPED;
@@ -631,7 +631,7 @@ capture_input_closed(capture_session *cap_session, gchar *msg)
/* close the currently loaded capture file */
cf_close((capture_file *)cap_session->cf);
- capture_start(capture_opts, cap_session,NULL); /*XXX is this NULL ok or we need an update_cb???*/
+ capture_start(capture_opts, cap_session, cap_session->cap_data_info, NULL); /*XXX is this NULL ok or we need an update_cb???*/
} else {
/* We're not doing a capture any more, so we don't have a save file. */
g_free(capture_opts->save_file);
diff --git a/ui/capture.h b/ui/capture.h
index 5057b82910..5da05ba949 100644
--- a/ui/capture.h
+++ b/ui/capture.h
@@ -30,6 +30,7 @@
*/
#include "capture_opts.h"
+#include "capture_info.h"
#include "capchild/capture_session.h"
#ifdef __cplusplus
@@ -66,7 +67,7 @@ capture_callback_remove(capture_callback_t func, gpointer user_data);
* @return TRUE if the capture starts successfully, FALSE otherwise.
*/
extern gboolean
-capture_start(capture_options *capture_opts, capture_session *cap_session, void(*update_cb)(void));
+capture_start(capture_options *capture_opts, capture_session *cap_session, info_data_t* cap_data, void(*update_cb)(void));
/** Stop a capture session (usually from a menu item). */
extern void
diff --git a/ui/capture_globals.h b/ui/capture_globals.h
index d7b9e77542..916bd37516 100644
--- a/ui/capture_globals.h
+++ b/ui/capture_globals.h
@@ -23,7 +23,7 @@
#ifndef __CAPTURE_GLOBALS_H__
#define __CAPTURE_GLOBALS_H__
-#include <capchild/capture_session.h>
+#include "capture_opts.h"
#ifdef __cplusplus
extern "C" {
@@ -31,8 +31,6 @@ extern "C" {
extern capture_options global_capture_opts;
-extern capture_session global_capture_session;
-
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/ui/gtk/capture_dlg.c b/ui/gtk/capture_dlg.c
index 14e8937bec..abb3fd00ae 100644
--- a/ui/gtk/capture_dlg.c
+++ b/ui/gtk/capture_dlg.c
@@ -5401,7 +5401,7 @@ capture_start_cb(GtkWidget *w _U_, gpointer d _U_)
this capture. */
collect_ifaces(&global_capture_opts);
- if (capture_start(&global_capture_opts, &global_capture_session, main_window_update)) {
+ if (capture_start(&global_capture_opts, &global_capture_session, &global_info_data, main_window_update)) {
/* The capture succeeded, which means the capture filters specified are
valid; add them to the recent capture filter lists for the interfaces.
diff --git a/ui/gtk/gtkglobals.h b/ui/gtk/gtkglobals.h
index 628685b6fb..e2fac873d7 100644
--- a/ui/gtk/gtkglobals.h
+++ b/ui/gtk/gtkglobals.h
@@ -37,6 +37,9 @@
* GTK global definitions. For example a pointer to the main application window.
*/
+#include <capchild/capture_session.h>
+#include <capture_info.h>
+
/** Application window. */
extern GtkWidget *top_level;
@@ -49,4 +52,8 @@ extern GtkWidget *byte_nb_ptr_gbl;
/** The filter text entry in the filter toolbar. */
extern GtkWidget *main_display_filter_widget;
+extern capture_session global_capture_session;
+
+extern info_data_t global_info_data;
+
#endif
diff --git a/ui/gtk/main.c b/ui/gtk/main.c
index add9afb484..245bc1e12c 100644
--- a/ui/gtk/main.c
+++ b/ui/gtk/main.c
@@ -224,6 +224,7 @@
#ifdef HAVE_LIBPCAP
capture_options global_capture_opts;
capture_session global_capture_session;
+info_data_t global_info_data;
#endif
capture_file cfile;
@@ -646,7 +647,7 @@ copy_selected_plist_cb(GtkWidget *w _U_, gpointer data _U_, COPY_SELECTED_E acti
{
case COPY_SELECTED_DESCRIPTION:
if (cfile.finfo_selected->rep &&
- strlen (cfile.finfo_selected->rep->representation) > 0) {
+ strlen(cfile.finfo_selected->rep->representation) > 0) {
g_string_append(gtk_text_str, cfile.finfo_selected->rep->representation);
}
break;
@@ -3297,7 +3298,7 @@ main(int argc, char *argv[])
to use for this capture. */
if (global_capture_opts.ifaces->len == 0)
collect_ifaces(&global_capture_opts);
- if (capture_start(&global_capture_opts, &global_capture_session,main_window_update)) {
+ if (capture_start(&global_capture_opts, &global_capture_session, &global_info_data,main_window_update)) {
/* The capture started. Open stat windows; we do so after creating
the main window, to avoid GTK warnings, and after successfully
opening the capture file, so we know we have something to compute
diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h
index 204eb99f6a..abd63e2910 100644
--- a/ui/qt/main_window.h
+++ b/ui/qt/main_window.h
@@ -87,6 +87,7 @@ public:
QString getFilter();
#ifdef HAVE_LIBPCAP
capture_session *captureSession() { return &cap_session_; }
+ info_data_t *captureInfoData() { return &info_data_; }
#endif
virtual QMenu *createPopupMenu();
@@ -151,6 +152,7 @@ private:
#ifdef HAVE_LIBPCAP
capture_session cap_session_;
CaptureInterfacesDialog capture_interfaces_dialog_;
+ info_data_t info_data_;
#endif
// Pipe input
diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp
index 40dc8e426e..cb6f8eff0f 100644
--- a/ui/qt/main_window_slots.cpp
+++ b/ui/qt/main_window_slots.cpp
@@ -849,7 +849,7 @@ void MainWindow::startCapture() {
collect_ifaces(&global_capture_opts);
CaptureFile::globalCapFile()->window = this;
- if (capture_start(&global_capture_opts, &cap_session_, main_window_update)) {
+ if (capture_start(&global_capture_opts, &cap_session_, &info_data_, main_window_update)) {
capture_options *capture_opts = cap_session_.capture_opts;
GString *interface_names;
diff --git a/wireshark-qt.cpp b/wireshark-qt.cpp
index fc9ef0c9d0..ec8b33cbab 100644
--- a/wireshark-qt.cpp
+++ b/wireshark-qt.cpp
@@ -1409,7 +1409,7 @@ int main(int argc, char *argv[])
if (global_capture_opts.ifaces->len == 0)
collect_ifaces(&global_capture_opts);
CaptureFile::globalCapFile()->window = main_w;
- if (capture_start(&global_capture_opts, main_w->captureSession(), main_window_update)) {
+ if (capture_start(&global_capture_opts, main_w->captureSession(), main_w->captureInfoData(), main_window_update)) {
/* The capture started. Open stat windows; we do so after creating
the main window, to avoid GTK warnings, and after successfully
opening the capture file, so we know we have something to compute