1 /* rtp_stream.c
2 * RTP streams summary addition for Wireshark
3 *
4 * Copyright 2003, Alcatel Business Systems
5 * By Lars Ruoff <lars.ruoff@gmx.net>
6 *
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
10 *
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 */
13
14 #include "config.h"
15
16 #include <stdlib.h>
17 #include <string.h>
18
19 #include "file.h"
20
21 #include <epan/epan.h>
22 #include <epan/packet.h>
23 #include <epan/tap.h>
24 #include <epan/dissectors/packet-rtp.h>
25 #include <epan/addr_resolv.h>
26
27 #include "ui/alert_box.h"
28 #include "ui/simple_dialog.h"
29 #include "ui/rtp_stream.h"
30 #include "ui/tap-rtp-common.h"
31 #include <wsutil/file_util.h>
32
33
34 /****************************************************************************/
35 /* scan for RTP streams */
36 void
show_tap_registration_error(GString * error_string)37 show_tap_registration_error(GString *error_string)
38 {
39 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
40 "%s", error_string->str);
41 }
42
43 /****************************************************************************/
44 /* scan for RTP streams */
rtpstream_scan(rtpstream_tapinfo_t * tapinfo,capture_file * cap_file,const char * fstring)45 void rtpstream_scan(rtpstream_tapinfo_t *tapinfo, capture_file *cap_file, const char *fstring)
46 {
47 gboolean was_registered;
48
49 if (!tapinfo || !cap_file) {
50 return;
51 }
52
53 was_registered = tapinfo->is_registered;
54 if (!tapinfo->is_registered)
55 register_tap_listener_rtpstream(tapinfo, fstring, show_tap_registration_error);
56
57 /* RTP_STREAM_DEBUG("scanning %s, filter: %s", cap_file->filename, fstring); */
58 tapinfo->mode = TAP_ANALYSE;
59 cf_retap_packets(cap_file);
60
61 if (!was_registered)
62 remove_tap_listener_rtpstream(tapinfo);
63 }
64
65
66 /****************************************************************************/
67 /* save rtp dump of stream_fwd */
rtpstream_save(rtpstream_tapinfo_t * tapinfo,capture_file * cap_file,rtpstream_info_t * stream,const gchar * filename)68 gboolean rtpstream_save(rtpstream_tapinfo_t *tapinfo, capture_file *cap_file, rtpstream_info_t* stream, const gchar *filename)
69 {
70 gboolean was_registered;
71
72 if (!tapinfo) {
73 return FALSE;
74 }
75
76 was_registered = tapinfo->is_registered;
77
78 /* open file for saving */
79 tapinfo->save_file = ws_fopen(filename, "wb");
80 if (tapinfo->save_file==NULL) {
81 open_failure_alert_box(filename, errno, TRUE);
82 return FALSE;
83 }
84
85 rtp_write_header(stream, tapinfo->save_file);
86 if (ferror(tapinfo->save_file)) {
87 write_failure_alert_box(filename, errno);
88 fclose(tapinfo->save_file);
89 return FALSE;
90 }
91
92 if (!tapinfo->is_registered)
93 register_tap_listener_rtpstream(tapinfo, NULL, show_tap_registration_error);
94
95 tapinfo->mode = TAP_SAVE;
96 tapinfo->filter_stream_fwd = stream;
97 cf_retap_packets(cap_file);
98 tapinfo->mode = TAP_ANALYSE;
99
100 if (!was_registered)
101 remove_tap_listener_rtpstream(tapinfo);
102
103 if (ferror(tapinfo->save_file)) {
104 write_failure_alert_box(filename, errno);
105 fclose(tapinfo->save_file);
106 return FALSE;
107 }
108
109 if (fclose(tapinfo->save_file) == EOF) {
110 write_failure_alert_box(filename, errno);
111 return FALSE;
112 }
113 return TRUE;
114 }
115
116 /****************************************************************************/
117 /* mark packets in stream_fwd or stream_rev */
rtpstream_mark(rtpstream_tapinfo_t * tapinfo,capture_file * cap_file,rtpstream_info_t * stream_fwd,rtpstream_info_t * stream_rev)118 void rtpstream_mark(rtpstream_tapinfo_t *tapinfo, capture_file *cap_file, rtpstream_info_t* stream_fwd, rtpstream_info_t* stream_rev)
119 {
120 gboolean was_registered;
121
122 if (!tapinfo) {
123 return;
124 }
125
126 was_registered = tapinfo->is_registered;
127
128 if (!tapinfo->is_registered)
129 register_tap_listener_rtpstream(tapinfo, NULL, show_tap_registration_error);
130
131 tapinfo->mode = TAP_MARK;
132 tapinfo->filter_stream_fwd = stream_fwd;
133 tapinfo->filter_stream_rev = stream_rev;
134 cf_retap_packets(cap_file);
135 tapinfo->mode = TAP_ANALYSE;
136
137 if (!was_registered)
138 remove_tap_listener_rtpstream(tapinfo);
139 }
140