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.3 1999/07/29 05:47:03 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>
43 static int proto_rtsp = -1;
45 static int is_rtsp_request_or_reply(const u_char *data, int linelen);
48 is_content_sdp(const u_char *line, int linelen)
50 const char *hdr = "Content-Type:";
51 size_t hdrlen = strlen(hdr);
52 const char *type = "application/sdp";
53 size_t typelen = strlen(type);
55 if (linelen < hdrlen || strncasecmp(hdr, line, hdrlen))
60 while (linelen > 0 && (*line == ' ' || *line == '\t')) {
65 if (linelen < typelen || strncasecmp(type, line, typelen))
70 if (linelen > 0 && !isspace(*line))
76 void dissect_rtsp(const u_char *pd, int offset, frame_data *fd,
79 proto_tree *rtsp_tree;
81 const u_char *data, *dataend;
82 const u_char *linep, *lineend, *eol;
88 dataend = data + END_OF_FRAME;
90 if (check_col(fd, COL_PROTOCOL))
91 col_add_str(fd, COL_PROTOCOL, "RTSP");
92 if (check_col(fd, COL_INFO)) {
94 * Put the first line from the buffer into the summary,
95 * if it's an RTSP request or reply.
96 * Otherwise, just call it a continuation.
98 lineend = find_line_end(data, dataend, &eol);
99 linelen = lineend - data;
100 if (is_rtsp_request_or_reply(data, linelen))
101 col_add_str(fd, COL_INFO, format_text(data, linelen));
103 col_add_str(fd, COL_INFO, "Continuation");
109 ti = proto_tree_add_item(tree, proto_rtsp, offset, END_OF_FRAME, NULL);
110 rtsp_tree = proto_item_add_subtree(ti, ETT_RTSP);
113 while (data < dataend) {
115 * Find the end of the line.
117 lineend = find_line_end(data, dataend, &eol);
118 linelen = lineend - data;
121 * OK, does it look like an RTSP request or
124 if (is_rtsp_request_or_reply(data, linelen))
128 * No. Does it look like a blank line (as would
129 * appear at the end of an RTSP request)?
136 if (strncmp(data, "\r\n", 2) == 0 ||
137 strncmp(data, "\n\r", 2) == 0)
142 * No. Does it look like a MIME header?
145 while (linep < lineend) {
148 break; /* not printable, not a MIME header */
168 * It's a tspecial, so it's not
169 * part of a token, so it's not
170 * a field name for the beginning
177 * This ends the token; we consider
178 * this to be a MIME header.
180 if (is_content_sdp(data, linelen))
188 * We don't consider this part of an RTSP request or
189 * reply, so we don't display it.
198 proto_tree_add_text(rtsp_tree, offset, linelen, "%s",
199 format_text(data, linelen));
206 dissect_sdp(pd, offset, fd, tree);
207 if (check_col(fd, COL_PROTOCOL))
208 col_add_str(fd, COL_PROTOCOL, "RTSP/SDP");
210 else if (rtsp_tree && data < dataend) {
211 proto_tree_add_text(rtsp_tree, offset, END_OF_FRAME,
212 "Data (%d bytes)", END_OF_FRAME);
216 const char *rtsp_methods[] = {
217 "DESCRIBE", "ANNOUNCE", "GET_PARAMETER", "OPTIONS",
218 "PAUSE", "PLAY", "RECORD", "REDIRECT", "SETUP",
219 "SET_PARAMETER", "TEARDOWN"
221 const int rtsp_nmethods = sizeof(rtsp_methods) / sizeof(*rtsp_methods);
224 is_rtsp_request_or_reply(const u_char *data, int linelen)
230 if (linelen >= 5 && !strncasecmp("RTSP/", data, 5))
233 /* Request Methods */
234 for (ii = 0; ii < rtsp_nmethods; ii++) {
235 len = strlen(rtsp_methods[ii]);
236 if (linelen >= len && !strncasecmp(rtsp_methods[ii], data, len))
244 proto_register_rtsp(void)
246 /* static hf_register_info hf[] = {
248 { "Name", "rtsp.abbreviation", TYPE, VALS_POINTER }},
251 proto_rtsp = proto_register_protocol("Real Time Streaming Protocol", "rtsp");
252 /* proto_register_field_array(proto_rtsp, hf, array_length(hf));*/