2003-09-24 07:48:12 +00:00
|
|
|
/* rtp_stream.c
|
2006-05-22 07:29:40 +00:00
|
|
|
* RTP streams summary addition for Wireshark
|
2003-09-24 07:48:12 +00:00
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2003-09-24 07:48:12 +00:00
|
|
|
*
|
|
|
|
* Copyright 2003, Alcatel Business Systems
|
|
|
|
* By Lars Ruoff <lars.ruoff@gmx.net>
|
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2003-09-24 07:48:12 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2008-04-13 03:32:24 +00:00
|
|
|
#include <string.h>
|
2003-09-24 07:48:12 +00:00
|
|
|
|
2004-06-29 20:51:26 +00:00
|
|
|
#ifdef HAVE_FCNTL_H
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
2003-09-24 07:48:12 +00:00
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
# include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
2008-04-13 03:32:24 +00:00
|
|
|
|
|
|
|
#include <epan/epan.h>
|
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <epan/tap.h>
|
|
|
|
#include <epan/dissectors/packet-rtp.h>
|
2005-03-02 23:22:11 +00:00
|
|
|
#include <epan/addr_resolv.h>
|
2003-09-24 07:48:12 +00:00
|
|
|
|
2008-04-13 03:32:24 +00:00
|
|
|
#include "../globals.h"
|
|
|
|
#include "../register.h"
|
|
|
|
#include "../alert_box.h"
|
|
|
|
#include "../simple_dialog.h"
|
|
|
|
#include "../tap-rtp-common.h"
|
2008-05-22 15:46:27 +00:00
|
|
|
#include <wsutil/file_util.h>
|
2008-04-13 03:32:24 +00:00
|
|
|
|
|
|
|
#include "gtk/rtp_stream.h"
|
|
|
|
#include "gtk/rtp_stream_dlg.h"
|
2008-08-05 17:33:14 +00:00
|
|
|
#include "gtk/main.h"
|
2008-04-13 03:32:24 +00:00
|
|
|
|
2008-09-21 14:50:05 +00:00
|
|
|
/* The one and only global rtpstream_tapinfo_t structure for tshark and wireshark.
|
|
|
|
*/
|
|
|
|
static rtpstream_tapinfo_t the_tapinfo_struct =
|
|
|
|
{0, NULL, 0, TAP_ANALYSE, NULL, NULL, NULL, 0, FALSE};
|
|
|
|
|
2005-01-01 12:49:54 +00:00
|
|
|
|
2003-09-24 07:48:12 +00:00
|
|
|
/****************************************************************************/
|
|
|
|
/* redraw the output */
|
2005-08-20 14:02:00 +00:00
|
|
|
static void rtpstream_draw(void *arg _U_)
|
2003-09-24 07:48:12 +00:00
|
|
|
{
|
|
|
|
/* XXX: see rtpstream_on_update in rtp_streams_dlg.c for comments
|
2008-06-29 15:51:43 +00:00
|
|
|
g_signal_emit_by_name(top_level, "signal_rtpstream_update");
|
2003-09-24 07:48:12 +00:00
|
|
|
*/
|
|
|
|
rtpstream_dlg_update(the_tapinfo_struct.strinfo_list);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* scan for RTP streams */
|
2004-01-18 16:21:12 +00:00
|
|
|
void rtpstream_scan(void)
|
2003-09-24 07:48:12 +00:00
|
|
|
{
|
|
|
|
gboolean was_registered = the_tapinfo_struct.is_registered;
|
|
|
|
if (!the_tapinfo_struct.is_registered)
|
|
|
|
register_tap_listener_rtp_stream();
|
|
|
|
|
|
|
|
the_tapinfo_struct.mode = TAP_ANALYSE;
|
2009-06-05 22:42:47 +00:00
|
|
|
cf_retap_packets(&cfile);
|
2003-09-24 07:48:12 +00:00
|
|
|
|
|
|
|
if (!was_registered)
|
|
|
|
remove_tap_listener_rtp_stream();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* save rtp dump of stream_fwd */
|
2004-01-25 02:24:44 +00:00
|
|
|
gboolean rtpstream_save(rtp_stream_info_t* stream, const gchar *filename)
|
2003-09-24 07:48:12 +00:00
|
|
|
{
|
|
|
|
gboolean was_registered = the_tapinfo_struct.is_registered;
|
|
|
|
/* open file for saving */
|
2008-05-22 15:46:27 +00:00
|
|
|
the_tapinfo_struct.save_file = ws_fopen(filename, "wb");
|
2003-09-24 07:48:12 +00:00
|
|
|
if (the_tapinfo_struct.save_file==NULL) {
|
2004-02-11 01:23:25 +00:00
|
|
|
open_failure_alert_box(filename, errno, TRUE);
|
2004-01-25 02:24:44 +00:00
|
|
|
return FALSE;
|
2003-09-24 07:48:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rtp_write_header(stream, the_tapinfo_struct.save_file);
|
2004-01-25 02:24:44 +00:00
|
|
|
if (ferror(the_tapinfo_struct.save_file)) {
|
2004-02-11 01:37:13 +00:00
|
|
|
write_failure_alert_box(filename, errno);
|
2004-01-25 02:24:44 +00:00
|
|
|
fclose(the_tapinfo_struct.save_file);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-09-24 07:48:12 +00:00
|
|
|
|
|
|
|
if (!the_tapinfo_struct.is_registered)
|
|
|
|
register_tap_listener_rtp_stream();
|
|
|
|
|
|
|
|
the_tapinfo_struct.mode = TAP_SAVE;
|
|
|
|
the_tapinfo_struct.filter_stream_fwd = stream;
|
2009-06-05 22:42:47 +00:00
|
|
|
cf_retap_packets(&cfile);
|
2003-09-24 07:48:12 +00:00
|
|
|
the_tapinfo_struct.mode = TAP_ANALYSE;
|
|
|
|
|
|
|
|
if (!was_registered)
|
|
|
|
remove_tap_listener_rtp_stream();
|
|
|
|
|
2004-01-25 02:24:44 +00:00
|
|
|
if (ferror(the_tapinfo_struct.save_file)) {
|
2004-02-11 01:37:13 +00:00
|
|
|
write_failure_alert_box(filename, errno);
|
2004-01-25 02:24:44 +00:00
|
|
|
fclose(the_tapinfo_struct.save_file);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fclose(the_tapinfo_struct.save_file) == EOF) {
|
2004-02-11 01:37:13 +00:00
|
|
|
write_failure_alert_box(filename, errno);
|
2004-01-25 02:24:44 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2003-09-24 07:48:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* mark packets in stream_fwd or stream_rev */
|
|
|
|
void rtpstream_mark(rtp_stream_info_t* stream_fwd, rtp_stream_info_t* stream_rev)
|
|
|
|
{
|
|
|
|
gboolean was_registered = the_tapinfo_struct.is_registered;
|
|
|
|
if (!the_tapinfo_struct.is_registered)
|
|
|
|
register_tap_listener_rtp_stream();
|
|
|
|
|
|
|
|
the_tapinfo_struct.mode = TAP_MARK;
|
|
|
|
the_tapinfo_struct.filter_stream_fwd = stream_fwd;
|
|
|
|
the_tapinfo_struct.filter_stream_rev = stream_rev;
|
2009-06-05 22:42:47 +00:00
|
|
|
cf_retap_packets(&cfile);
|
2003-09-24 07:48:12 +00:00
|
|
|
the_tapinfo_struct.mode = TAP_ANALYSE;
|
|
|
|
|
|
|
|
if (!was_registered)
|
|
|
|
remove_tap_listener_rtp_stream();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************/
|
2004-01-18 16:21:12 +00:00
|
|
|
const rtpstream_tapinfo_t* rtpstream_get_info(void)
|
2003-09-24 07:48:12 +00:00
|
|
|
{
|
|
|
|
return &the_tapinfo_struct;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* TAP INTERFACE */
|
|
|
|
/****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
void
|
|
|
|
remove_tap_listener_rtp_stream(void)
|
|
|
|
{
|
|
|
|
if (the_tapinfo_struct.is_registered) {
|
|
|
|
protect_thread_critical_region();
|
|
|
|
remove_tap_listener(&the_tapinfo_struct);
|
|
|
|
unprotect_thread_critical_region();
|
|
|
|
|
|
|
|
the_tapinfo_struct.is_registered = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
void
|
|
|
|
register_tap_listener_rtp_stream(void)
|
|
|
|
{
|
|
|
|
GString *error_string;
|
|
|
|
|
|
|
|
if (!the_tapinfo_struct.is_registered) {
|
|
|
|
error_string = register_tap_listener("rtp", &the_tapinfo_struct,
|
2009-06-05 22:42:47 +00:00
|
|
|
NULL, 0, rtpstream_reset_cb, rtpstream_packet,
|
2005-01-01 12:49:54 +00:00
|
|
|
rtpstream_draw);
|
2003-09-24 07:48:12 +00:00
|
|
|
|
|
|
|
if (error_string != NULL) {
|
2004-02-12 22:24:28 +00:00
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
|
2008-10-31 09:53:56 +00:00
|
|
|
"%s", error_string->str);
|
2003-09-24 07:48:12 +00:00
|
|
|
g_string_free(error_string, TRUE);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
the_tapinfo_struct.is_registered = TRUE;
|
|
|
|
}
|
|
|
|
}
|