2 * Routines for RTSP packet disassembly (RFC 2326)
4 * Jason Lango <jal@netapp.com>
5 * Liberally copied from packet-http.c, by Guy Harris <guy@alum.mit.edu>
7 * $Id: packet-rtsp.c,v 1.8 2000/02/15 21:03:04 gram Exp $
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@zing.org>
11 * Copyright 1998 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #ifdef HAVE_SYS_TYPES_H
34 #include <sys/types.h>
42 #include "packet-sdp.h"
44 static int proto_rtsp = -1;
45 static gint ett_rtsp = -1;
47 static int hf_rtsp_method = -1;
48 static int hf_rtsp_url = -1;
49 static int hf_rtsp_status = -1;
51 static int process_rtsp_request_or_reply(const u_char *data, int offset,
52 int linelen, proto_tree *tree);
55 is_content_sdp(const u_char *line, int linelen)
57 const char *hdr = "Content-Type:";
58 size_t hdrlen = strlen(hdr);
59 const char *type = "application/sdp";
60 size_t typelen = strlen(type);
62 if (linelen < hdrlen || strncasecmp(hdr, line, hdrlen))
67 while (linelen > 0 && (*line == ' ' || *line == '\t')) {
72 if (linelen < typelen || strncasecmp(type, line, typelen))
77 if (linelen > 0 && !isspace(*line))
83 void dissect_rtsp(const u_char *pd, int offset, frame_data *fd,
86 proto_tree *rtsp_tree;
88 const u_char *data, *dataend;
89 const u_char *linep, *lineend, *eol;
96 dataend = data + END_OF_FRAME;
97 end_offset = offset + END_OF_FRAME;
101 ti = proto_tree_add_item(tree, proto_rtsp, offset,
103 rtsp_tree = proto_item_add_subtree(ti, ett_rtsp);
106 if (check_col(fd, COL_PROTOCOL))
107 col_add_str(fd, COL_PROTOCOL, "RTSP");
108 if (check_col(fd, COL_INFO)) {
110 * Put the first line from the buffer into the summary
111 * if it's an RTSP request or reply. Otherwise, just call
114 lineend = find_line_end(data, dataend, &eol);
115 linelen = lineend - data;
116 if (process_rtsp_request_or_reply(data, offset, linelen,
118 col_add_str(fd, COL_INFO, format_text(data, linelen));
120 col_add_str(fd, COL_INFO, "Continuation");
126 if (offset >= end_offset)
128 while (data < dataend) {
130 * Find the end of the line.
132 lineend = find_line_end(data, dataend, &eol);
133 linelen = lineend - data;
136 * OK, does it look like an RTSP request or
139 if (process_rtsp_request_or_reply(data, offset, linelen,
144 * No. Does it look like a blank line (as would
145 * appear at the end of an RTSP request)?
152 if (strncmp(data, "\r\n", 2) == 0 ||
153 strncmp(data, "\n\r", 2) == 0)
158 * No. Does it look like a MIME header?
161 while (linep < lineend) {
164 break; /* not printable, not a MIME header */
184 * It's a tspecial, so it's not
185 * part of a token, so it's not
186 * a field name for the beginning
193 * This ends the token; we consider
194 * this to be a MIME header.
196 if (is_content_sdp(data, linelen))
204 * We don't consider this part of an RTSP request or
205 * reply, so we don't display it.
213 proto_tree_add_text(rtsp_tree, offset, linelen, "%s",
214 format_text(data, linelen));
220 dissect_sdp(pd, offset, fd, tree);
221 if (check_col(fd, COL_PROTOCOL))
222 col_add_str(fd, COL_PROTOCOL, "RTSP/SDP");
224 else if (data < dataend) {
225 proto_tree_add_text(rtsp_tree, offset, END_OF_FRAME,
226 "Data (%d bytes)", END_OF_FRAME);
231 proto_tree_add_text(rtsp_tree, end_offset, 0,
232 "Unexpected end of packet");
235 const char *rtsp_methods[] = {
236 "DESCRIBE", "ANNOUNCE", "GET_PARAMETER", "OPTIONS",
237 "PAUSE", "PLAY", "RECORD", "REDIRECT", "SETUP",
238 "SET_PARAMETER", "TEARDOWN"
240 const int rtsp_nmethods = sizeof(rtsp_methods) / sizeof(*rtsp_methods);
243 process_rtsp_request_or_reply(const u_char *data, int offset, int linelen,
247 const u_char *lineend = data + linelen;
250 if (linelen >= 5 && !strncasecmp("RTSP/", data, 5)) {
253 const u_char *status = data;
254 const u_char *status_start;
255 unsigned int status_i = 0;
256 while (status < lineend && !isspace(*status))
258 while (status < lineend && isspace(*status))
260 status_start = status;
261 while (status < lineend && isdigit(*status))
262 status_i = status_i * 10 + *status++ - '0';
263 proto_tree_add_item_hidden(tree, hf_rtsp_status,
264 offset + (status_start - data),
265 status - status_start, status_i);
270 /* Request Methods */
271 for (ii = 0; ii < rtsp_nmethods; ii++) {
272 size_t len = strlen(rtsp_methods[ii]);
273 if (linelen >= len && !strncasecmp(rtsp_methods[ii], data, len))
276 if (ii == rtsp_nmethods)
281 const u_char *url_start;
285 proto_tree_add_item_hidden(tree, hf_rtsp_method, offset,
286 strlen(rtsp_methods[ii]), rtsp_methods[ii]);
290 while (url < lineend && !isspace(*url))
292 while (url < lineend && isspace(*url))
295 while (url < lineend && !isspace(*url))
297 tmp_url = g_malloc(url - url_start + 1);
298 memcpy(tmp_url, url_start, url - url_start);
299 tmp_url[url - url_start] = 0;
300 proto_tree_add_item_hidden(tree, hf_rtsp_url,
301 offset + (url_start - data), url - url_start, tmp_url);
308 proto_register_rtsp(void)
310 static gint *ett[] = {
313 static hf_register_info hf[] = {
315 { "Method", "rtsp.method", FT_STRING, BASE_NONE, NULL, 0 }},
317 { "URL", "rtsp.url", FT_STRING, BASE_NONE, NULL, 0 }},
319 { "Status", "rtsp.status", FT_UINT32, BASE_DEC, NULL, 0 }},
322 proto_rtsp = proto_register_protocol("Real Time Streaming Protocol",
324 proto_register_field_array(proto_rtsp, hf, array_length(hf));
325 proto_register_subtree_array(ett, array_length(ett));