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.2 1999/07/07 22:51:53 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 is_rtsp_request_or_reply(const u_char *data, int linelen);
46 is_content_sdp(const u_char *line, int linelen)
48 const char *hdr = "Content-Type:";
49 size_t hdrlen = strlen(hdr);
50 const char *type = "application/sdp";
51 size_t typelen = strlen(type);
53 if (linelen < hdrlen || strncasecmp(hdr, line, hdrlen))
58 while (linelen > 0 && (*line == ' ' || *line == '\t')) {
63 if (linelen < typelen || strncasecmp(type, line, typelen))
68 if (linelen > 0 && !isspace(*line))
74 void dissect_rtsp(const u_char *pd, int offset, frame_data *fd,
77 proto_tree *rtsp_tree;
79 const u_char *data, *dataend;
80 const u_char *linep, *lineend, *eol;
86 dataend = data + END_OF_FRAME;
88 if (check_col(fd, COL_PROTOCOL))
89 col_add_str(fd, COL_PROTOCOL, "RTSP");
90 if (check_col(fd, COL_INFO)) {
92 * Put the first line from the buffer into the summary,
93 * if it's an RTSP request or reply.
94 * Otherwise, just call it a continuation.
96 lineend = find_line_end(data, dataend, &eol);
97 linelen = lineend - data;
98 if (is_rtsp_request_or_reply(data, linelen))
99 col_add_str(fd, COL_INFO, format_text(data, linelen));
101 col_add_str(fd, COL_INFO, "Continuation");
107 ti = proto_tree_add_text(tree, offset, END_OF_FRAME,
108 "Real Time Streaming Protocol");
109 rtsp_tree = proto_item_add_subtree(ti, ETT_RTSP);
112 while (data < dataend) {
114 * Find the end of the line.
116 lineend = find_line_end(data, dataend, &eol);
117 linelen = lineend - data;
120 * OK, does it look like an RTSP request or
123 if (is_rtsp_request_or_reply(data, linelen))
127 * No. Does it look like a blank line (as would
128 * appear at the end of an RTSP request)?
135 if (strncmp(data, "\r\n", 2) == 0 ||
136 strncmp(data, "\n\r", 2) == 0)
141 * No. Does it look like a MIME header?
144 while (linep < lineend) {
147 break; /* not printable, not a MIME header */
167 * It's a tspecial, so it's not
168 * part of a token, so it's not
169 * a field name for the beginning
176 * This ends the token; we consider
177 * this to be a MIME header.
179 if (is_content_sdp(data, linelen))
187 * We don't consider this part of an RTSP request or
188 * reply, so we don't display it.
197 proto_tree_add_text(rtsp_tree, offset, linelen, "%s",
198 format_text(data, linelen));
205 dissect_sdp(pd, offset, fd, tree);
206 if (check_col(fd, COL_PROTOCOL))
207 col_add_str(fd, COL_PROTOCOL, "RTSP/SDP");
209 else if (rtsp_tree && data < dataend) {
210 proto_tree_add_text(rtsp_tree, offset, END_OF_FRAME,
211 "Data (%d bytes)", END_OF_FRAME);
215 const char *rtsp_methods[] = {
216 "DESCRIBE", "ANNOUNCE", "GET_PARAMETER", "OPTIONS",
217 "PAUSE", "PLAY", "RECORD", "REDIRECT", "SETUP",
218 "SET_PARAMETER", "TEARDOWN"
220 const int rtsp_nmethods = sizeof(rtsp_methods) / sizeof(*rtsp_methods);
223 is_rtsp_request_or_reply(const u_char *data, int linelen)
229 if (linelen >= 5 && !strncasecmp("RTSP/", data, 5))
232 /* Request Methods */
233 for (ii = 0; ii < rtsp_nmethods; ii++) {
234 len = strlen(rtsp_methods[ii]);
235 if (linelen >= len && !strncasecmp(rtsp_methods[ii], data, len))