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
|
|
|
*
|
|
|
|
* 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
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2003-09-24 07:48:12 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-20 01:48:30 +00:00
|
|
|
#include "config.h"
|
2009-08-26 19:27:49 +00:00
|
|
|
|
2013-11-10 15:59:37 +00:00
|
|
|
#include <stdlib.h>
|
2008-04-13 03:32:24 +00:00
|
|
|
#include <string.h>
|
2003-09-24 07:48:12 +00:00
|
|
|
|
2015-01-15 01:25:56 +00:00
|
|
|
#include "file.h"
|
|
|
|
|
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
|
|
|
|
2012-01-16 01:07:52 +00:00
|
|
|
#include "ui/alert_box.h"
|
|
|
|
#include "ui/simple_dialog.h"
|
2013-10-24 23:47:30 +00:00
|
|
|
#include "ui/rtp_stream.h"
|
2013-06-26 02:12:12 +00:00
|
|
|
#include "ui/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
|
|
|
|
2005-01-01 12:49:54 +00:00
|
|
|
|
2003-09-24 07:48:12 +00:00
|
|
|
/****************************************************************************/
|
|
|
|
/* redraw the output */
|
2015-01-15 01:25:56 +00:00
|
|
|
static void rtpstream_draw(void *ti_ptr)
|
2003-09-24 07:48:12 +00:00
|
|
|
{
|
2015-01-15 01:25:56 +00:00
|
|
|
rtpstream_tapinfo_t *tapinfo = (rtpstream_tapinfo_t *)ti_ptr;
|
2003-09-24 07:48:12 +00:00
|
|
|
/* XXX: see rtpstream_on_update in rtp_streams_dlg.c for comments
|
2014-11-16 15:42:32 +00:00
|
|
|
g_signal_emit_by_name(top_level, "signal_rtpstream_update");
|
2003-09-24 07:48:12 +00:00
|
|
|
*/
|
2015-01-15 01:25:56 +00:00
|
|
|
if (tapinfo && tapinfo->tap_draw) {
|
2014-12-13 00:51:40 +00:00
|
|
|
/* RTP_STREAM_DEBUG("streams: %d packets: %d", tapinfo->nstreams, tapinfo->npackets); */
|
2015-02-06 23:49:31 +00:00
|
|
|
tapinfo->tap_draw(tapinfo);
|
2015-01-15 01:25:56 +00:00
|
|
|
}
|
2014-11-16 15:42:32 +00:00
|
|
|
return;
|
2003-09-24 07:48:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* scan for RTP streams */
|
2015-05-15 02:53:16 +00:00
|
|
|
void rtpstream_scan(rtpstream_tapinfo_t *tapinfo, capture_file *cap_file, const char *fstring)
|
2003-09-24 07:48:12 +00:00
|
|
|
{
|
2015-01-15 01:25:56 +00:00
|
|
|
gboolean was_registered;
|
|
|
|
|
|
|
|
if (!tapinfo || !cap_file) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
was_registered = tapinfo->is_registered;
|
|
|
|
if (!tapinfo->is_registered)
|
2015-05-15 02:53:16 +00:00
|
|
|
register_tap_listener_rtp_stream(tapinfo, fstring);
|
2003-09-24 07:48:12 +00:00
|
|
|
|
2014-12-13 00:51:40 +00:00
|
|
|
/* RTP_STREAM_DEBUG("scanning %s, filter: %s", cap_file->filename, fstring); */
|
2015-01-15 01:25:56 +00:00
|
|
|
tapinfo->mode = TAP_ANALYSE;
|
|
|
|
cf_retap_packets(cap_file);
|
2003-09-24 07:48:12 +00:00
|
|
|
|
2014-11-16 15:42:32 +00:00
|
|
|
if (!was_registered)
|
2015-01-15 01:25:56 +00:00
|
|
|
remove_tap_listener_rtp_stream(tapinfo);
|
2003-09-24 07:48:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* save rtp dump of stream_fwd */
|
2015-01-15 01:25:56 +00:00
|
|
|
gboolean rtpstream_save(rtpstream_tapinfo_t *tapinfo, capture_file *cap_file, rtp_stream_info_t* stream, const gchar *filename)
|
2003-09-24 07:48:12 +00:00
|
|
|
{
|
2015-01-15 01:25:56 +00:00
|
|
|
gboolean was_registered;
|
|
|
|
|
|
|
|
if (!tapinfo) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
was_registered = tapinfo->is_registered;
|
|
|
|
|
2014-11-16 15:42:32 +00:00
|
|
|
/* open file for saving */
|
2015-01-15 01:25:56 +00:00
|
|
|
tapinfo->save_file = ws_fopen(filename, "wb");
|
|
|
|
if (tapinfo->save_file==NULL) {
|
2014-11-16 15:42:32 +00:00
|
|
|
open_failure_alert_box(filename, errno, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-01-15 01:25:56 +00:00
|
|
|
rtp_write_header(stream, tapinfo->save_file);
|
|
|
|
if (ferror(tapinfo->save_file)) {
|
2014-11-16 15:42:32 +00:00
|
|
|
write_failure_alert_box(filename, errno);
|
2015-01-15 01:25:56 +00:00
|
|
|
fclose(tapinfo->save_file);
|
2014-11-16 15:42:32 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-01-15 01:25:56 +00:00
|
|
|
if (!tapinfo->is_registered)
|
2015-05-15 02:53:16 +00:00
|
|
|
register_tap_listener_rtp_stream(tapinfo, NULL);
|
2014-11-16 15:42:32 +00:00
|
|
|
|
2015-01-15 01:25:56 +00:00
|
|
|
tapinfo->mode = TAP_SAVE;
|
|
|
|
tapinfo->filter_stream_fwd = stream;
|
|
|
|
cf_retap_packets(cap_file);
|
|
|
|
tapinfo->mode = TAP_ANALYSE;
|
2014-11-16 15:42:32 +00:00
|
|
|
|
|
|
|
if (!was_registered)
|
2015-01-15 01:25:56 +00:00
|
|
|
remove_tap_listener_rtp_stream(tapinfo);
|
2014-11-16 15:42:32 +00:00
|
|
|
|
2015-01-15 01:25:56 +00:00
|
|
|
if (ferror(tapinfo->save_file)) {
|
2014-11-16 15:42:32 +00:00
|
|
|
write_failure_alert_box(filename, errno);
|
2015-01-15 01:25:56 +00:00
|
|
|
fclose(tapinfo->save_file);
|
2014-11-16 15:42:32 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-01-15 01:25:56 +00:00
|
|
|
if (fclose(tapinfo->save_file) == EOF) {
|
2014-11-16 15:42:32 +00:00
|
|
|
write_failure_alert_box(filename, errno);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2003-09-24 07:48:12 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 01:25:56 +00:00
|
|
|
/****************************************************************************/
|
|
|
|
/* compare the endpoints of two RTP streams */
|
|
|
|
gboolean rtp_stream_info_is_reverse(const rtp_stream_info_t *stream_a, rtp_stream_info_t *stream_b)
|
|
|
|
{
|
|
|
|
if (stream_a == NULL || stream_b == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-10-21 18:46:49 +00:00
|
|
|
if ((addresses_equal(&(stream_a->src_addr), &(stream_b->dest_addr)))
|
2015-01-15 01:25:56 +00:00
|
|
|
&& (stream_a->src_port == stream_b->dest_port)
|
2015-10-21 18:46:49 +00:00
|
|
|
&& (addresses_equal(&(stream_a->dest_addr), &(stream_b->src_addr)))
|
2015-01-15 01:25:56 +00:00
|
|
|
&& (stream_a->dest_port == stream_b->src_port))
|
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-09-24 07:48:12 +00:00
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* mark packets in stream_fwd or stream_rev */
|
2015-01-15 01:25:56 +00:00
|
|
|
void rtpstream_mark(rtpstream_tapinfo_t *tapinfo, capture_file *cap_file, rtp_stream_info_t* stream_fwd, rtp_stream_info_t* stream_rev)
|
2003-09-24 07:48:12 +00:00
|
|
|
{
|
2015-01-15 01:25:56 +00:00
|
|
|
gboolean was_registered;
|
2014-11-16 15:42:32 +00:00
|
|
|
|
2015-01-15 01:25:56 +00:00
|
|
|
if (!tapinfo) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-16 15:42:32 +00:00
|
|
|
|
2015-01-15 01:25:56 +00:00
|
|
|
was_registered = tapinfo->is_registered;
|
2003-09-24 07:48:12 +00:00
|
|
|
|
2015-01-15 01:25:56 +00:00
|
|
|
if (!tapinfo->is_registered)
|
2015-05-15 02:53:16 +00:00
|
|
|
register_tap_listener_rtp_stream(tapinfo, NULL);
|
2003-09-24 07:48:12 +00:00
|
|
|
|
2015-01-15 01:25:56 +00:00
|
|
|
tapinfo->mode = TAP_MARK;
|
|
|
|
tapinfo->filter_stream_fwd = stream_fwd;
|
|
|
|
tapinfo->filter_stream_rev = stream_rev;
|
|
|
|
cf_retap_packets(cap_file);
|
|
|
|
tapinfo->mode = TAP_ANALYSE;
|
|
|
|
|
|
|
|
if (!was_registered)
|
|
|
|
remove_tap_listener_rtp_stream(tapinfo);
|
2003-09-24 07:48:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* TAP INTERFACE */
|
|
|
|
/****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
void
|
2015-01-15 01:25:56 +00:00
|
|
|
remove_tap_listener_rtp_stream(rtpstream_tapinfo_t *tapinfo)
|
2003-09-24 07:48:12 +00:00
|
|
|
{
|
2015-01-15 01:25:56 +00:00
|
|
|
if (tapinfo && tapinfo->is_registered) {
|
|
|
|
remove_tap_listener(tapinfo);
|
|
|
|
tapinfo->is_registered = FALSE;
|
2014-11-16 15:42:32 +00:00
|
|
|
}
|
2003-09-24 07:48:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
void
|
2015-05-15 02:53:16 +00:00
|
|
|
register_tap_listener_rtp_stream(rtpstream_tapinfo_t *tapinfo, const char *fstring)
|
2003-09-24 07:48:12 +00:00
|
|
|
{
|
2014-11-16 15:42:32 +00:00
|
|
|
GString *error_string;
|
|
|
|
|
2015-01-15 01:25:56 +00:00
|
|
|
if (!tapinfo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tapinfo->is_registered) {
|
|
|
|
error_string = register_tap_listener("rtp", tapinfo,
|
2015-05-15 02:53:16 +00:00
|
|
|
fstring, 0, rtpstream_reset_cb, rtpstream_packet,
|
2014-11-16 15:42:32 +00:00
|
|
|
rtpstream_draw);
|
|
|
|
|
|
|
|
if (error_string != NULL) {
|
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
|
|
|
|
"%s", error_string->str);
|
|
|
|
g_string_free(error_string, TRUE);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2015-01-15 01:25:56 +00:00
|
|
|
tapinfo->is_registered = TRUE;
|
2014-11-16 15:42:32 +00:00
|
|
|
}
|
2003-09-24 07:48:12 +00:00
|
|
|
}
|
2014-11-16 15:42:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|