/* packet-sip.c
* Routines for the Session Initiation Protocol (SIP) dissection.
* RFC 2543
- *
+ *
* TODO: Pay attention to Content-Type: It might not always be SDP.
* Add hf_* fields for filtering support.
* Add sip msg body dissection based on Content-Type for:
* check for other
*
* Copyright 2000, Heikki Vatiainen <hessu@cs.tut.fi>
- * Copyright 2001, Jean-Francois Mule <jfm@clarent.com>
+ * Copyright 2001, Jean-Francois Mule <jfm@cablelabs.com>
*
- * $Id: packet-sip.c,v 1.27 2002/05/08 20:29:46 guy Exp $
+ * $Id: packet-sip.c,v 1.33 2002/10/02 18:51:10 gerald Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
* Copyright 1998 Gerald Combs
*
* Copied from packet-cops.c
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static gboolean sip_is_request(tvbuff_t *tvb, gint eol);
static gboolean sip_is_known_request(tvbuff_t *tvb, guint32 offset);
static gint sip_get_msg_offset(tvbuff_t *tvb, guint32 offset);
-
+
static dissector_handle_t sdp_handle;
static dissector_handle_t data_handle;
* "tvb_get_ptr()" call s below won't throw exceptions.
*/
offset = 0;
- eol = tvb_find_line_end(tvb, 0, -1, &next_offset);
+ eol = tvb_find_line_end(tvb, 0, -1, &next_offset, FALSE);
/* XXX - Check for a valid status message as well. */
is_request = sip_is_request(tvb, eol);
is_known_request = sip_is_known_request(tvb, 0);
if (tvb_strneql(tvb, 0, SIP2_HDR, SIP2_HDR_LEN) != 0 && ! is_request)
goto bad;
- if (check_col(pinfo->cinfo, COL_PROTOCOL))
+ if (check_col(pinfo->cinfo, COL_PROTOCOL))
col_set_str(pinfo->cinfo, COL_PROTOCOL, "SIP");
-
+
req_descr = is_known_request ? "Request" : "Unknown request";
if (check_col(pinfo->cinfo, COL_INFO))
col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %s",
/* - 2 since we have a CRLF separating the message-body */
while (msg_offset - 2 > (int) offset) {
- eol = tvb_find_line_end(tvb, offset, -1, &next_offset);
+ eol = tvb_find_line_end(tvb, offset, -1, &next_offset,
+ FALSE);
proto_tree_add_text(hdr_tree, tvb, offset, next_offset - offset, "%s",
tvb_format_text(tvb, offset, eol));
offset = next_offset;
* So we first check if the frame is really meant for us.
*/
- /* check for a request */
+ /*
+ * Check for a response.
+ * First, make sure we have enough data to do the check.
+ */
+ if (!tvb_bytes_exist(tvb, 0, SIP2_HDR_LEN)) {
+ /*
+ * We don't.
+ */
+ return FALSE;
+ }
+ /*
+ * Now see if we have a response header; they begin with
+ * "SIP/2.0".
+ */
if (tvb_strneql(tvb, 0, SIP2_HDR, SIP2_HDR_LEN) != 0) {
/*
- * Not a request; check for a response.
+ * We don't, so this isn't a response; check for a request.
+ * They *end* with "SIP/2.0".
*/
- eol = tvb_find_line_end(tvb, 0, -1, &next_offset);
- if ((eol > (gint)SIP2_HDR_LEN) &&
- (tvb_strneql(tvb, eol - SIP2_HDR_LEN + 1, SIP2_HDR , SIP2_HDR_LEN - 1) != 0)) {
+ eol = tvb_find_line_end(tvb, 0, -1, &next_offset, FALSE);
+ if (eol <= (gint)SIP2_HDR_LEN) {
/*
- * Not a response, either.
+ * The line isn't long enough to end with "SIP/2.0".
+ */
+ return FALSE;
+ }
+ if (!tvb_bytes_exist(tvb, eol - SIP2_HDR_LEN, SIP2_HDR_LEN)) {
+ /*
+ * We don't have enough of the data in the line
+ * to check.
+ */
+ return FALSE;
+ }
+
+ if (tvb_strneql(tvb, eol - SIP2_HDR_LEN, SIP2_HDR, SIP2_HDR_LEN - 1) != 0) {
+ /*
+ * Not a request, either.
*/
return FALSE;
}
return TRUE;
}
-
/* Returns the offset to the start of the optional message-body, or
* -1 if not found.
*/
while ((eol = tvb_find_guint8(tvb, offset, -1, '\r')) > 0
&& tvb_bytes_exist(tvb, eol, 4)) {
- if (tvb_get_guint8(tvb, eol + 1) == '\n' &&
- tvb_get_guint8(tvb, eol + 2) == '\r' &&
+ if (tvb_get_guint8(tvb, eol + 1) == '\n' &&
+ tvb_get_guint8(tvb, eol + 2) == '\r' &&
tvb_get_guint8(tvb, eol + 3) == '\n')
return eol + 4;
offset = eol + 2;
/* From section 4.1 of RFC 2543:
*
* Request-Line = Method SP Request-URI SP SIP-Version CRLF
- */
+ */
static gboolean sip_is_request(tvbuff_t *tvb, gint eol)
{
if (req_colon_pos < 0 || req_colon_pos > ver_start)
return FALSE;
/* XXX - Check for a proper URI prefix? */
-
+
/* Do we have a proper version string? */
if (tvb_strneql(tvb, ver_start, SIP2_HDR, SIP2_HDR_LEN))
return TRUE;
/* Register the protocol with Ethereal */
void proto_register_sip(void)
-{
+{
/* Setup list of header fields */
static hf_register_info hf[] = {