nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 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 | * This program is free software; you can redistribute it and/or |
||
12 | * modify it under the terms of the GNU General Public License |
||
13 | * as published by the Free Software Foundation; either version 2 |
||
14 | * of the License, or (at your option) any later version. |
||
15 | * |
||
16 | * This program is distributed in the hope that it will be useful, |
||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
19 | * GNU General Public License for more details. |
||
20 | * |
||
21 | * You should have received a copy of the GNU General Public License |
||
22 | * along with this program; if not, write to the Free Software |
||
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
||
24 | */ |
||
25 | |||
26 | #include "config.h" |
||
27 | |||
28 | #include <stdlib.h> |
||
29 | #include <string.h> |
||
30 | |||
31 | #include "file.h" |
||
32 | |||
33 | #include <epan/epan.h> |
||
34 | #include <epan/packet.h> |
||
35 | #include <epan/tap.h> |
||
36 | #include <epan/dissectors/packet-rtp.h> |
||
37 | #include <epan/addr_resolv.h> |
||
38 | |||
39 | #include "ui/alert_box.h" |
||
40 | #include "ui/simple_dialog.h" |
||
41 | #include "ui/rtp_stream.h" |
||
42 | #include "ui/tap-rtp-common.h" |
||
43 | #include <wsutil/file_util.h> |
||
44 | |||
45 | |||
46 | /****************************************************************************/ |
||
47 | /* redraw the output */ |
||
48 | static void rtpstream_draw(void *ti_ptr) |
||
49 | { |
||
50 | rtpstream_tapinfo_t *tapinfo = (rtpstream_tapinfo_t *)ti_ptr; |
||
51 | /* XXX: see rtpstream_on_update in rtp_streams_dlg.c for comments |
||
52 | g_signal_emit_by_name(top_level, "signal_rtpstream_update"); |
||
53 | */ |
||
54 | if (tapinfo && tapinfo->tap_draw) { |
||
55 | /* RTP_STREAM_DEBUG("streams: %d packets: %d", tapinfo->nstreams, tapinfo->npackets); */ |
||
56 | tapinfo->tap_draw(tapinfo); |
||
57 | } |
||
58 | return; |
||
59 | } |
||
60 | |||
61 | |||
62 | /****************************************************************************/ |
||
63 | /* scan for RTP streams */ |
||
64 | void rtpstream_scan(rtpstream_tapinfo_t *tapinfo, capture_file *cap_file, const char *fstring) |
||
65 | { |
||
66 | gboolean was_registered; |
||
67 | |||
68 | if (!tapinfo || !cap_file) { |
||
69 | return; |
||
70 | } |
||
71 | |||
72 | was_registered = tapinfo->is_registered; |
||
73 | if (!tapinfo->is_registered) |
||
74 | register_tap_listener_rtp_stream(tapinfo, fstring); |
||
75 | |||
76 | /* RTP_STREAM_DEBUG("scanning %s, filter: %s", cap_file->filename, fstring); */ |
||
77 | tapinfo->mode = TAP_ANALYSE; |
||
78 | cf_retap_packets(cap_file); |
||
79 | |||
80 | if (!was_registered) |
||
81 | remove_tap_listener_rtp_stream(tapinfo); |
||
82 | } |
||
83 | |||
84 | |||
85 | /****************************************************************************/ |
||
86 | /* save rtp dump of stream_fwd */ |
||
87 | gboolean rtpstream_save(rtpstream_tapinfo_t *tapinfo, capture_file *cap_file, rtp_stream_info_t* stream, const gchar *filename) |
||
88 | { |
||
89 | gboolean was_registered; |
||
90 | |||
91 | if (!tapinfo) { |
||
92 | return FALSE; |
||
93 | } |
||
94 | |||
95 | was_registered = tapinfo->is_registered; |
||
96 | |||
97 | /* open file for saving */ |
||
98 | tapinfo->save_file = ws_fopen(filename, "wb"); |
||
99 | if (tapinfo->save_file==NULL) { |
||
100 | open_failure_alert_box(filename, errno, TRUE); |
||
101 | return FALSE; |
||
102 | } |
||
103 | |||
104 | rtp_write_header(stream, tapinfo->save_file); |
||
105 | if (ferror(tapinfo->save_file)) { |
||
106 | write_failure_alert_box(filename, errno); |
||
107 | fclose(tapinfo->save_file); |
||
108 | return FALSE; |
||
109 | } |
||
110 | |||
111 | if (!tapinfo->is_registered) |
||
112 | register_tap_listener_rtp_stream(tapinfo, NULL); |
||
113 | |||
114 | tapinfo->mode = TAP_SAVE; |
||
115 | tapinfo->filter_stream_fwd = stream; |
||
116 | cf_retap_packets(cap_file); |
||
117 | tapinfo->mode = TAP_ANALYSE; |
||
118 | |||
119 | if (!was_registered) |
||
120 | remove_tap_listener_rtp_stream(tapinfo); |
||
121 | |||
122 | if (ferror(tapinfo->save_file)) { |
||
123 | write_failure_alert_box(filename, errno); |
||
124 | fclose(tapinfo->save_file); |
||
125 | return FALSE; |
||
126 | } |
||
127 | |||
128 | if (fclose(tapinfo->save_file) == EOF) { |
||
129 | write_failure_alert_box(filename, errno); |
||
130 | return FALSE; |
||
131 | } |
||
132 | return TRUE; |
||
133 | } |
||
134 | |||
135 | /****************************************************************************/ |
||
136 | /* compare the endpoints of two RTP streams */ |
||
137 | gboolean rtp_stream_info_is_reverse(const rtp_stream_info_t *stream_a, rtp_stream_info_t *stream_b) |
||
138 | { |
||
139 | if (stream_a == NULL || stream_b == NULL) |
||
140 | return FALSE; |
||
141 | |||
142 | if ((addresses_equal(&(stream_a->src_addr), &(stream_b->dest_addr))) |
||
143 | && (stream_a->src_port == stream_b->dest_port) |
||
144 | && (addresses_equal(&(stream_a->dest_addr), &(stream_b->src_addr))) |
||
145 | && (stream_a->dest_port == stream_b->src_port)) |
||
146 | return TRUE; |
||
147 | else |
||
148 | return FALSE; |
||
149 | } |
||
150 | |||
151 | /****************************************************************************/ |
||
152 | /* mark packets in stream_fwd or stream_rev */ |
||
153 | void rtpstream_mark(rtpstream_tapinfo_t *tapinfo, capture_file *cap_file, rtp_stream_info_t* stream_fwd, rtp_stream_info_t* stream_rev) |
||
154 | { |
||
155 | gboolean was_registered; |
||
156 | |||
157 | if (!tapinfo) { |
||
158 | return; |
||
159 | } |
||
160 | |||
161 | was_registered = tapinfo->is_registered; |
||
162 | |||
163 | if (!tapinfo->is_registered) |
||
164 | register_tap_listener_rtp_stream(tapinfo, NULL); |
||
165 | |||
166 | tapinfo->mode = TAP_MARK; |
||
167 | tapinfo->filter_stream_fwd = stream_fwd; |
||
168 | tapinfo->filter_stream_rev = stream_rev; |
||
169 | cf_retap_packets(cap_file); |
||
170 | tapinfo->mode = TAP_ANALYSE; |
||
171 | |||
172 | if (!was_registered) |
||
173 | remove_tap_listener_rtp_stream(tapinfo); |
||
174 | } |
||
175 | |||
176 | |||
177 | /****************************************************************************/ |
||
178 | /* TAP INTERFACE */ |
||
179 | /****************************************************************************/ |
||
180 | |||
181 | /****************************************************************************/ |
||
182 | void |
||
183 | remove_tap_listener_rtp_stream(rtpstream_tapinfo_t *tapinfo) |
||
184 | { |
||
185 | if (tapinfo && tapinfo->is_registered) { |
||
186 | remove_tap_listener(tapinfo); |
||
187 | tapinfo->is_registered = FALSE; |
||
188 | } |
||
189 | } |
||
190 | |||
191 | |||
192 | /****************************************************************************/ |
||
193 | void |
||
194 | register_tap_listener_rtp_stream(rtpstream_tapinfo_t *tapinfo, const char *fstring) |
||
195 | { |
||
196 | GString *error_string; |
||
197 | |||
198 | if (!tapinfo) { |
||
199 | return; |
||
200 | } |
||
201 | |||
202 | if (!tapinfo->is_registered) { |
||
203 | error_string = register_tap_listener("rtp", tapinfo, |
||
204 | fstring, 0, rtpstream_reset_cb, rtpstream_packet, |
||
205 | rtpstream_draw); |
||
206 | |||
207 | if (error_string != NULL) { |
||
208 | simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, |
||
209 | "%s", error_string->str); |
||
210 | g_string_free(error_string, TRUE); |
||
211 | exit(1); |
||
212 | } |
||
213 | |||
214 | tapinfo->is_registered = TRUE; |
||
215 | } |
||
216 | } |
||
217 | |||
218 | /* |
||
219 | * Editor modelines - http://www.wireshark.org/tools/modelines.html |
||
220 | * |
||
221 | * Local variables: |
||
222 | * c-basic-offset: 4 |
||
223 | * tab-width: 8 |
||
224 | * indent-tabs-mode: nil |
||
225 | * End: |
||
226 | * |
||
227 | * vi: set shiftwidth=4 tabstop=8 expandtab: |
||
228 | * :indentSize=4:tabSize=8:noTabs=true: |
||
229 | */ |