2 * Routines for RTSP packet disassembly
4 * Jason Lango <jal@netapp.com>
5 * Liberally copied from packet-http.c, by Guy Harris <guy@netapp.com>
7 * $Id: packet-rtsp.c,v 1.4 1999/11/16 11:42:53 guy 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>
43 static int proto_rtsp = -1;
45 static gint ett_rtsp = -1;
47 static int is_rtsp_request_or_reply(const u_char *data, int linelen);
50 is_content_sdp(const u_char *line, int linelen)
52 const char *hdr = "Content-Type:";
53 size_t hdrlen = strlen(hdr);
54 const char *type = "application/sdp";
55 size_t typelen = strlen(type);
57 if (linelen < hdrlen || strncasecmp(hdr, line, hdrlen))
62 while (linelen > 0 && (*line == ' ' || *line == '\t')) {
67 if (linelen < typelen || strncasecmp(type, line, typelen))
72 if (linelen > 0 && !isspace(*line))
78 void dissect_rtsp(const u_char *pd, int offset, frame_data *fd,
81 proto_tree *rtsp_tree;
83 const u_char *data, *dataend;
84 const u_char *linep, *lineend, *eol;
90 dataend = data + END_OF_FRAME;
92 if (check_col(fd, COL_PROTOCOL))
93 col_add_str(fd, COL_PROTOCOL, "RTSP");
94 if (check_col(fd, COL_INFO)) {
96 * Put the first line from the buffer into the summary,
97 * if it's an RTSP request or reply.
98 * Otherwise, just call it a continuation.
100 lineend = find_line_end(data, dataend, &eol);
101 linelen = lineend - data;
102 if (is_rtsp_request_or_reply(data, linelen))
103 col_add_str(fd, COL_INFO, format_text(data, linelen));
105 col_add_str(fd, COL_INFO, "Continuation");
111 ti = proto_tree_add_item(tree, proto_rtsp, offset, END_OF_FRAME, NULL);
112 rtsp_tree = proto_item_add_subtree(ti, ett_rtsp);
115 while (data < dataend) {
117 * Find the end of the line.
119 lineend = find_line_end(data, dataend, &eol);
120 linelen = lineend - data;
123 * OK, does it look like an RTSP request or
126 if (is_rtsp_request_or_reply(data, linelen))
130 * No. Does it look like a blank line (as would
131 * appear at the end of an RTSP request)?
138 if (strncmp(data, "\r\n", 2) == 0 ||
139 strncmp(data, "\n\r", 2) == 0)
144 * No. Does it look like a MIME header?
147 while (linep < lineend) {
150 break; /* not printable, not a MIME header */
170 * It's a tspecial, so it's not
171 * part of a token, so it's not
172 * a field name for the beginning
179 * This ends the token; we consider
180 * this to be a MIME header.
182 if (is_content_sdp(data, linelen))
190 * We don't consider this part of an RTSP request or
191 * reply, so we don't display it.
200 proto_tree_add_text(rtsp_tree, offset, linelen, "%s",
201 format_text(data, linelen));
208 dissect_sdp(pd, offset, fd, tree);
209 if (check_col(fd, COL_PROTOCOL))
210 col_add_str(fd, COL_PROTOCOL, "RTSP/SDP");
212 else if (rtsp_tree && data < dataend) {
213 proto_tree_add_text(rtsp_tree, offset, END_OF_FRAME,
214 "Data (%d bytes)", END_OF_FRAME);
218 const char *rtsp_methods[] = {
219 "DESCRIBE", "ANNOUNCE", "GET_PARAMETER", "OPTIONS",
220 "PAUSE", "PLAY", "RECORD", "REDIRECT", "SETUP",
221 "SET_PARAMETER", "TEARDOWN"
223 const int rtsp_nmethods = sizeof(rtsp_methods) / sizeof(*rtsp_methods);
226 is_rtsp_request_or_reply(const u_char *data, int linelen)
232 if (linelen >= 5 && !strncasecmp("RTSP/", data, 5))
235 /* Request Methods */
236 for (ii = 0; ii < rtsp_nmethods; ii++) {
237 len = strlen(rtsp_methods[ii]);
238 if (linelen >= len && !strncasecmp(rtsp_methods[ii], data, len))
246 proto_register_rtsp(void)
248 /* static hf_register_info hf[] = {
250 { "Name", "rtsp.abbreviation", TYPE, VALS_POINTER }},
252 static gint *ett[] = {
256 proto_rtsp = proto_register_protocol("Real Time Streaming Protocol", "rtsp");
257 /* proto_register_field_array(proto_rtsp, hf, array_length(hf));*/
258 proto_register_subtree_array(ett, array_length(ett));