2 * RTP streams summary addition for Wireshark
6 * Copyright 2003, Alcatel Business Systems
7 * By Lars Ruoff <lars.ruoff@gmx.net>
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
37 #ifdef HAVE_SYS_TYPES_H
38 # include <sys/types.h>
42 #include <epan/epan.h>
43 #include <epan/packet.h>
45 #include <epan/dissectors/packet-rtp.h>
46 #include <epan/addr_resolv.h>
48 #include "../globals.h"
49 #include "../register.h"
50 #include "../alert_box.h"
51 #include "../simple_dialog.h"
52 #include "../tap-rtp-common.h"
53 #include <wsutil/file_util.h>
55 #include "gtk/rtp_stream.h"
56 #include "gtk/rtp_stream_dlg.h"
59 /* The one and only global rtpstream_tapinfo_t structure for tshark and wireshark.
61 static rtpstream_tapinfo_t the_tapinfo_struct =
62 {0, NULL, 0, TAP_ANALYSE, NULL, NULL, NULL, 0, FALSE};
65 /****************************************************************************/
66 /* redraw the output */
67 static void rtpstream_draw(void *arg _U_)
69 /* XXX: see rtpstream_on_update in rtp_streams_dlg.c for comments
70 g_signal_emit_by_name(top_level, "signal_rtpstream_update");
72 rtpstream_dlg_update(the_tapinfo_struct.strinfo_list);
77 /****************************************************************************/
78 /* scan for RTP streams */
79 void rtpstream_scan(void)
81 gboolean was_registered = the_tapinfo_struct.is_registered;
82 if (!the_tapinfo_struct.is_registered)
83 register_tap_listener_rtp_stream();
85 the_tapinfo_struct.mode = TAP_ANALYSE;
86 cf_retap_packets(&cfile, FALSE);
89 remove_tap_listener_rtp_stream();
93 /****************************************************************************/
94 /* save rtp dump of stream_fwd */
95 gboolean rtpstream_save(rtp_stream_info_t* stream, const gchar *filename)
97 gboolean was_registered = the_tapinfo_struct.is_registered;
98 /* open file for saving */
99 the_tapinfo_struct.save_file = ws_fopen(filename, "wb");
100 if (the_tapinfo_struct.save_file==NULL) {
101 open_failure_alert_box(filename, errno, TRUE);
105 rtp_write_header(stream, the_tapinfo_struct.save_file);
106 if (ferror(the_tapinfo_struct.save_file)) {
107 write_failure_alert_box(filename, errno);
108 fclose(the_tapinfo_struct.save_file);
112 if (!the_tapinfo_struct.is_registered)
113 register_tap_listener_rtp_stream();
115 the_tapinfo_struct.mode = TAP_SAVE;
116 the_tapinfo_struct.filter_stream_fwd = stream;
117 cf_retap_packets(&cfile, FALSE);
118 the_tapinfo_struct.mode = TAP_ANALYSE;
121 remove_tap_listener_rtp_stream();
123 if (ferror(the_tapinfo_struct.save_file)) {
124 write_failure_alert_box(filename, errno);
125 fclose(the_tapinfo_struct.save_file);
129 if (fclose(the_tapinfo_struct.save_file) == EOF) {
130 write_failure_alert_box(filename, errno);
137 /****************************************************************************/
138 /* mark packets in stream_fwd or stream_rev */
139 void rtpstream_mark(rtp_stream_info_t* stream_fwd, rtp_stream_info_t* stream_rev)
141 gboolean was_registered = the_tapinfo_struct.is_registered;
142 if (!the_tapinfo_struct.is_registered)
143 register_tap_listener_rtp_stream();
145 the_tapinfo_struct.mode = TAP_MARK;
146 the_tapinfo_struct.filter_stream_fwd = stream_fwd;
147 the_tapinfo_struct.filter_stream_rev = stream_rev;
148 cf_retap_packets(&cfile, FALSE);
149 the_tapinfo_struct.mode = TAP_ANALYSE;
152 remove_tap_listener_rtp_stream();
156 /****************************************************************************/
157 const rtpstream_tapinfo_t* rtpstream_get_info(void)
159 return &the_tapinfo_struct;
163 /****************************************************************************/
165 /****************************************************************************/
167 /****************************************************************************/
169 remove_tap_listener_rtp_stream(void)
171 if (the_tapinfo_struct.is_registered) {
172 protect_thread_critical_region();
173 remove_tap_listener(&the_tapinfo_struct);
174 unprotect_thread_critical_region();
176 the_tapinfo_struct.is_registered = FALSE;
181 /****************************************************************************/
183 register_tap_listener_rtp_stream(void)
185 GString *error_string;
187 if (!the_tapinfo_struct.is_registered) {
188 error_string = register_tap_listener("rtp", &the_tapinfo_struct,
189 NULL, rtpstream_reset_cb, rtpstream_packet,
192 if (error_string != NULL) {
193 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
194 "%s", error_string->str);
195 g_string_free(error_string, TRUE);
199 the_tapinfo_struct.is_registered = TRUE;