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.
39 #ifdef HAVE_SYS_TYPES_H
40 # include <sys/types.h>
44 #include <epan/epan.h>
45 #include <epan/packet.h>
47 #include <epan/dissectors/packet-rtp.h>
48 #include <epan/addr_resolv.h>
50 #include "../globals.h"
51 #include "../alert_box.h"
52 #include "../simple_dialog.h"
53 #include "../tap-rtp-common.h"
54 #include <wsutil/file_util.h>
56 #include "gtk/rtp_stream.h"
57 #include "gtk/rtp_stream_dlg.h"
60 /* The one and only global rtpstream_tapinfo_t structure for tshark and wireshark.
62 static rtpstream_tapinfo_t the_tapinfo_struct =
63 {0, NULL, 0, TAP_ANALYSE, NULL, NULL, NULL, 0, FALSE};
66 /****************************************************************************/
67 /* redraw the output */
68 static void rtpstream_draw(void *arg _U_)
70 /* XXX: see rtpstream_on_update in rtp_streams_dlg.c for comments
71 g_signal_emit_by_name(top_level, "signal_rtpstream_update");
73 rtpstream_dlg_update(the_tapinfo_struct.strinfo_list);
78 /****************************************************************************/
79 /* scan for RTP streams */
80 void rtpstream_scan(void)
82 gboolean was_registered = the_tapinfo_struct.is_registered;
83 if (!the_tapinfo_struct.is_registered)
84 register_tap_listener_rtp_stream();
86 the_tapinfo_struct.mode = TAP_ANALYSE;
87 cf_retap_packets(&cfile);
90 remove_tap_listener_rtp_stream();
94 /****************************************************************************/
95 /* save rtp dump of stream_fwd */
96 gboolean rtpstream_save(rtp_stream_info_t* stream, const gchar *filename)
98 gboolean was_registered = the_tapinfo_struct.is_registered;
99 /* open file for saving */
100 the_tapinfo_struct.save_file = ws_fopen(filename, "wb");
101 if (the_tapinfo_struct.save_file==NULL) {
102 open_failure_alert_box(filename, errno, TRUE);
106 rtp_write_header(stream, the_tapinfo_struct.save_file);
107 if (ferror(the_tapinfo_struct.save_file)) {
108 write_failure_alert_box(filename, errno);
109 fclose(the_tapinfo_struct.save_file);
113 if (!the_tapinfo_struct.is_registered)
114 register_tap_listener_rtp_stream();
116 the_tapinfo_struct.mode = TAP_SAVE;
117 the_tapinfo_struct.filter_stream_fwd = stream;
118 cf_retap_packets(&cfile);
119 the_tapinfo_struct.mode = TAP_ANALYSE;
122 remove_tap_listener_rtp_stream();
124 if (ferror(the_tapinfo_struct.save_file)) {
125 write_failure_alert_box(filename, errno);
126 fclose(the_tapinfo_struct.save_file);
130 if (fclose(the_tapinfo_struct.save_file) == EOF) {
131 write_failure_alert_box(filename, errno);
138 /****************************************************************************/
139 /* mark packets in stream_fwd or stream_rev */
140 void rtpstream_mark(rtp_stream_info_t* stream_fwd, rtp_stream_info_t* stream_rev)
142 gboolean was_registered = the_tapinfo_struct.is_registered;
143 if (!the_tapinfo_struct.is_registered)
144 register_tap_listener_rtp_stream();
146 the_tapinfo_struct.mode = TAP_MARK;
147 the_tapinfo_struct.filter_stream_fwd = stream_fwd;
148 the_tapinfo_struct.filter_stream_rev = stream_rev;
149 cf_retap_packets(&cfile);
150 the_tapinfo_struct.mode = TAP_ANALYSE;
153 remove_tap_listener_rtp_stream();
157 /****************************************************************************/
158 const rtpstream_tapinfo_t* rtpstream_get_info(void)
160 return &the_tapinfo_struct;
164 /****************************************************************************/
166 /****************************************************************************/
168 /****************************************************************************/
170 remove_tap_listener_rtp_stream(void)
172 if (the_tapinfo_struct.is_registered) {
173 protect_thread_critical_region();
174 remove_tap_listener(&the_tapinfo_struct);
175 unprotect_thread_critical_region();
177 the_tapinfo_struct.is_registered = FALSE;
182 /****************************************************************************/
184 register_tap_listener_rtp_stream(void)
186 GString *error_string;
188 if (!the_tapinfo_struct.is_registered) {
189 error_string = register_tap_listener("rtp", &the_tapinfo_struct,
190 NULL, 0, rtpstream_reset_cb, rtpstream_packet,
193 if (error_string != NULL) {
194 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
195 "%s", error_string->str);
196 g_string_free(error_string, TRUE);
200 the_tapinfo_struct.is_registered = TRUE;