Multicast Stream: Move mcast_stream.[ch] to ui

Preparation to add Multicast Stream Dialog on Qt (Add extern C...)

Change-Id: Ic8bc39a18dba607d6da116df799de7847ce8e4c8
Reviewed-on: https://code.wireshark.org/review/6984
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Alexis La Goutte 2014-10-27 23:00:54 +01:00 committed by Michael Mann
parent d7ee0952d1
commit 0310132a82
8 changed files with 97 additions and 66 deletions

View File

@ -37,6 +37,7 @@ set(COMMON_UI_SRC
iface_lists.c
io_graph_item.c
language.c
mcast_stream.c
packet_list_utils.c
persfilepath_opt.c
preference_utils.c

View File

@ -58,6 +58,7 @@ WIRESHARK_UI_SRC = \
io_graph_item.c \
language.c \
help_url.c \
mcast_stream.c \
packet_list_utils.c \
persfilepath_opt.c \
preference_utils.c \
@ -96,6 +97,7 @@ noinst_HEADERS = \
iface_lists.h \
io_graph_item.h \
language.h \
mcast_stream.h \
main_statusbar.h \
persfilepath_opt.h \
preference_utils.h \

View File

@ -75,7 +75,6 @@ set(WIRESHARK_GTK_SRC
main_toolbar.c
main_welcome.c
manual_addr_resolv.c
mcast_stream.c
packet_history.c
packet_list_store.c
packet_list.c

View File

@ -96,7 +96,6 @@ WIRESHARK_GTK_SRC = \
main_titlebar.c \
main_toolbar.c \
main_welcome.c \
mcast_stream.c \
packet_history.c \
packet_list_store.c \
packet_list.c \
@ -271,8 +270,7 @@ noinst_HEADERS = \
main_toolbar_private.h \
main_welcome.h \
manual_addr_resolv.h \
mcast_stream.h \
mcast_stream_dlg.h \
mcast_stream_dlg.h \
mtp3_stat.h \
network_icons.h \
old-gtk-compat.h \

View File

@ -43,14 +43,21 @@
#include "ui/gtk/gui_stat_menu.h"
#include "ui/gtk/mcast_stream_dlg.h"
#include "ui/gtk/mcast_stream.h"
#include "ui/gtk/dlg_utils.h"
#include "ui/gtk/gui_utils.h"
#include "ui/gtk/gtkglobals.h"
#include "ui/gtk/stock_icons.h"
static void mcaststream_dlg_update(void *ti_ptr);
void register_tap_listener_mcast_stream_dlg(void);
/****************************************************************************/
/* the one and only global mcaststream_tapinfo_t structure for tshark and wireshark.
*/
static mcaststream_tapinfo_t the_tapinfo_struct =
{mcaststream_dlg_update, 0, NULL, 0, NULL, 0, FALSE};
/* Capture callback data keys */
#define E_MCAST_ENTRY_1 "burst_interval"
#define E_MCAST_ENTRY_2 "burst_alarm"
@ -103,14 +110,14 @@ static void
mcaststream_on_destroy(GObject *object _U_, gpointer user_data _U_)
{
/* Remove the stream tap listener */
remove_tap_listener_mcast_stream();
remove_tap_listener_mcast_stream(&the_tapinfo_struct);
/* Is there a params window open? */
if (mcast_params_dlg != NULL)
window_destroy(mcast_params_dlg);
/* Clean up memory used by stream tap */
mcaststream_reset((mcaststream_tapinfo_t*)mcaststream_get_info());
mcaststream_reset(mcaststream_dlg_get_tapinfo());
/* Note that we no longer have a "Mcast Streams" dialog box. */
mcast_stream_dlg = NULL;
@ -166,7 +173,7 @@ mcaststream_on_filter(GtkButton *button _U_, gpointer user_data _U_)
#if 0
main_filter_packets(&cfile, filter_string, FALSE);
mcaststream_dlg_update(mcaststream_get_info()->strinfo_list);
mcaststream_dlg_update(mcaststream_dlg_get_tapinfo()->strinfo_list);
#endif
}
@ -269,7 +276,7 @@ mcast_params_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w)
window_destroy(GTK_WIDGET(parent_w));
/* Clean up memory used by stream tap */
mcaststream_reset((mcaststream_tapinfo_t*)mcaststream_get_info());
mcaststream_reset((mcaststream_tapinfo_t*)mcaststream_dlg_get_tapinfo());
/* retap all packets */
cf_retap_packets(&cfile);
@ -431,9 +438,9 @@ add_to_list_store(mcast_stream_info_t* strinfo)
g_snprintf(label_text, sizeof(label_text),
"Detected %d Multicast streams, Average Bw: %.1f Mbps Max Bw: %.1f Mbps Max burst: %d / %dms Max buffer: %.1f KB",
++streams_nb,
mcaststream_get_info()->allstreams->average_bw, mcaststream_get_info()->allstreams->element.maxbw,
mcaststream_get_info()->allstreams->element.topburstsize, mcast_stream_burstint,
(float)(mcaststream_get_info()->allstreams->element.topbuffusage)/1000);
mcaststream_dlg_get_tapinfo()->allstreams->average_bw, mcaststream_dlg_get_tapinfo()->allstreams->element.maxbw,
mcaststream_dlg_get_tapinfo()->allstreams->element.topburstsize, mcast_stream_burstint,
(float)(mcaststream_dlg_get_tapinfo()->allstreams->element.topbuffusage)/1000);
gtk_label_set_text(GTK_LABEL(top_label), label_text);
g_snprintf(label_text, sizeof(label_text), "\nBurst int: %u ms Burst alarm: %u pps Buffer alarm: %u Bytes Stream empty speed: %u Kbps Total empty speed: %u Kbps\n",
@ -743,8 +750,17 @@ mcaststream_dlg_create(void)
/* update the contents of the dialog box clist */
/* list: pointer to list of mcast_stream_info_t* */
void
mcaststream_dlg_update(GList *list)
mcaststream_dlg_update(void *ti_ptr)
{
GList *list;
mcaststream_tapinfo_t *tapinfo = (mcaststream_tapinfo_t *)ti_ptr;
if (!tapinfo) {
return;
}
list = tapinfo->strinfo_list;
if (mcast_stream_dlg != NULL) {
gtk_list_store_clear(list_store);
streams_nb = 0;
@ -762,6 +778,14 @@ mcaststream_dlg_update(GList *list)
last_list = list;
}
#if 0
static void
mcaststream_dlg_mark_packet(mcaststream_tapinfo_t *tapinfo _U_, frame_data *fd) {
if (!fd) return;
cf_mark_frame(&cfile, fd);
}
#endif
/****************************************************************************/
/* update the contents of the dialog box clist */
@ -791,13 +815,13 @@ void
mcaststream_launch(GtkAction *action _U_, gpointer user_data _U_)
{
/* Register the tap listener */
register_tap_listener_mcast_stream();
register_tap_listener_mcast_stream(&the_tapinfo_struct);
/* Scan for Mcast streams (redissect all packets) */
mcaststream_scan();
mcaststream_scan(&the_tapinfo_struct, &cfile);
/* Show the dialog box with the list of streams */
mcaststream_dlg_show(mcaststream_get_info()->strinfo_list);
mcaststream_dlg_show(the_tapinfo_struct.strinfo_list);
/* Tap listener will be removed and cleaned up in mcaststream_on_destroy */
}
@ -808,6 +832,10 @@ register_tap_listener_mcast_stream_dlg(void)
{
}
mcaststream_tapinfo_t *mcaststream_dlg_get_tapinfo(void) {
return &the_tapinfo_struct;
}
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*

View File

@ -30,6 +30,8 @@
#ifndef __MCAST_STREAM_DLG_H__
#define __MCAST_STREAM_DLG_H__
#include "ui/mcast_stream.h"
/** @file
* @ingroup dialog_group
* "Mcast Stream Analysis" dialog box.
@ -43,10 +45,12 @@
void mcaststream_dlg_show(GList *list);
/**
* Update the contents of the dialog box clist with that of list.
* Retrieves a constant reference to the unique info structure of the
* rtp_streams tap listener.
* The user should not modify the data pointed to.
*
* @param list pointer to list of mcast_stream_info_t*
* @return Pointer to an rtpstream_tapinfo_t
*/
void mcaststream_dlg_update(GList *list);
mcaststream_tapinfo_t *mcaststream_dlg_get_tapinfo(void);
#endif /* __MCAST_STREAM_DLG_H__ */

View File

@ -39,7 +39,7 @@
#include <time.h>
#include <string.h>
#include <gtk/gtk.h>
#include "file.h"
#include <epan/epan.h>
#include <epan/address.h>
@ -48,13 +48,9 @@
#include <epan/to_str.h>
#include "ui/alert_box.h"
#include "ui/mcast_stream.h"
#include "ui/simple_dialog.h"
#include "ui/gtk/mcast_stream.h"
#include "ui/gtk/mcast_stream_dlg.h"
#include "ui/gtk/main.h"
#include "ui/gtk/stock_icons.h"
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
#endif
@ -72,12 +68,6 @@ static void buffusagecalc(mcast_stream_info_t *strinfo, packet_info *pinfo, d
static void slidingwindow(mcast_stream_info_t *strinfo, packet_info *pinfo);
/****************************************************************************/
/* the one and only global mcaststream_tapinfo_t structure */
static mcaststream_tapinfo_t the_tapinfo_struct =
{0, NULL, 0, NULL, 0, FALSE};
/****************************************************************************/
/* GCompareFunc style comparison function for _mcast_stream_info */
static gint
@ -142,12 +132,15 @@ mcaststream_reset_cb(void *arg)
/****************************************************************************/
/* redraw the output */
static void
mcaststream_draw(void *arg _U_)
mcaststream_draw(void *ti_ptr)
{
mcaststream_tapinfo_t *tapinfo = (mcaststream_tapinfo_t *)ti_ptr;
/* XXX: see mcaststream_on_update in mcast_streams_dlg.c for comments
g_signal_emit_by_name(top_level, "signal_mcaststream_update");
*/
mcaststream_dlg_update(the_tapinfo_struct.strinfo_list);
if (tapinfo && tapinfo->tap_draw) {
tapinfo->tap_draw(ti_ptr);
}
return;
}
@ -295,50 +288,51 @@ mcaststream_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const
/****************************************************************************/
/* scan for Mcast streams */
void
mcaststream_scan(void)
mcaststream_scan(mcaststream_tapinfo_t *tapinfo, capture_file *cap_file)
{
gboolean was_registered = the_tapinfo_struct.is_registered;
if (!the_tapinfo_struct.is_registered)
register_tap_listener_mcast_stream();
gboolean was_registered;
cf_retap_packets(&cfile);
if (!tapinfo || !cap_file) {
return;
}
was_registered = tapinfo->is_registered;
if (!tapinfo->is_registered)
register_tap_listener_mcast_stream(tapinfo);
cf_retap_packets(cap_file);
if (!was_registered)
remove_tap_listener_mcast_stream();
remove_tap_listener_mcast_stream(tapinfo);
}
/****************************************************************************/
const mcaststream_tapinfo_t *
mcaststream_get_info(void)
{
return &the_tapinfo_struct;
}
/****************************************************************************/
/* TAP INTERFACE */
/****************************************************************************/
/****************************************************************************/
void
remove_tap_listener_mcast_stream(void)
remove_tap_listener_mcast_stream(mcaststream_tapinfo_t *tapinfo)
{
if (the_tapinfo_struct.is_registered) {
remove_tap_listener(&the_tapinfo_struct);
the_tapinfo_struct.is_registered = FALSE;
if (tapinfo && tapinfo->is_registered) {
remove_tap_listener(tapinfo);
tapinfo->is_registered = FALSE;
}
}
/****************************************************************************/
void
register_tap_listener_mcast_stream(void)
register_tap_listener_mcast_stream(mcaststream_tapinfo_t *tapinfo)
{
GString *error_string;
if (!the_tapinfo_struct.is_registered) {
error_string = register_tap_listener("udp", &the_tapinfo_struct,
if (!tapinfo) {
return;
}
if (!tapinfo->is_registered) {
error_string = register_tap_listener("udp", tapinfo,
NULL, 0, mcaststream_reset_cb, mcaststream_packet,
mcaststream_draw);
@ -349,7 +343,7 @@ register_tap_listener_mcast_stream(void)
exit(1);
}
the_tapinfo_struct.is_registered = TRUE;
tapinfo->is_registered = TRUE;
}
}

View File

@ -30,6 +30,12 @@
#ifndef __MCAST_STREAM_H__
#define __MCAST_STREAM_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <epan/tap.h>
#define MAX_SPEED 200000
/* typedefs for sliding window and buffer size */
@ -80,6 +86,7 @@ typedef struct _mcast_stream_info {
/* structure that holds the information about all detected streams */
/* struct holding all information of the tap */
typedef struct _mcaststream_tapinfo {
tap_draw_cb tap_draw; /**< tap draw callback */
int nstreams; /* number of streams in the list */
GList* strinfo_list; /* list with all streams */
guint32 npackets; /* total number of mcast packets of all streams */
@ -106,19 +113,13 @@ extern gint32 mcast_stream_cumulemptyspeed;
* So whenever mcast_stream.c is added to the list of WIRESHARK_TAP_SRCs, the tap will be registered on startup.
* If not, it will be registered on demand by the mcast_streams and mcast_analysis functions that need it.
*/
void register_tap_listener_mcast_stream(void);
void register_tap_listener_mcast_stream(mcaststream_tapinfo_t *tapinfo);
/*
* Removes the mcast_streams tap listener (if not already done)
* From that point on, the Mcast streams list won't be updated any more.
*/
void remove_tap_listener_mcast_stream(void);
/*
* Retrieves a constant reference to the unique info structure of the mcast_streams tap listener.
* The user should not modify the data pointed to.
*/
const mcaststream_tapinfo_t* mcaststream_get_info(void);
void remove_tap_listener_mcast_stream(mcaststream_tapinfo_t *tapinfo);
/*
* Cleans up memory of mcast streams tap.
@ -129,7 +130,11 @@ void mcaststream_reset(mcaststream_tapinfo_t *tapinfo);
* Scans all packets for Mcast streams and updates the Mcast streams list.
* (redissects all packets)
*/
void mcaststream_scan(void);
void mcaststream_scan(mcaststream_tapinfo_t *tapinfo, capture_file *cap_file);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __MCAST_STREAM_H__ */