Updates from Heikki Vatiainen.
svn path=/trunk/; revision=2612
This commit is contained in:
parent
b9d2dd7151
commit
9226b24e60
65
packet-sip.c
65
packet-sip.c
|
@ -2,13 +2,12 @@
|
|||
* Routines for the Session Initiation Protocol (SIP) dissection.
|
||||
* RFC 2543
|
||||
*
|
||||
* TODO: Make sure that any of CRLF, CR or LF is treated as valid line terminator.
|
||||
* Pay attention to Content-Type: It might not always be SDP.
|
||||
* TODO: Pay attention to Content-Type: It might not always be SDP.
|
||||
* Add hf_* fields for filtering support.
|
||||
*
|
||||
* Copyright 2000, Heikki Vatiainen <hessu@cs.tut.fi>
|
||||
*
|
||||
* $Id: packet-sip.c,v 1.2 2000/11/10 06:50:36 guy Exp $
|
||||
* $Id: packet-sip.c,v 1.3 2000/11/11 19:57:09 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -64,17 +63,16 @@ static const char *sip_methods[] = {
|
|||
"REGISTER"
|
||||
};
|
||||
|
||||
static int sip_is_request(const char *line);
|
||||
static guint8 *sip_kill_version(guint8 *orig, guint8 *killed);
|
||||
static int sip_is_request(tvbuff_t *tvb, guint32 offset);
|
||||
static gint sip_get_msg_offset(tvbuff_t *tvb, guint32 offset);
|
||||
|
||||
/* Code to actually dissect the packets */
|
||||
static void dissect_sip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
||||
{
|
||||
guint8 buf[1500], tmp[1500];
|
||||
guint32 offset;
|
||||
gint eol, msg_offset;
|
||||
gint eol, next_offset, msg_offset;
|
||||
tvbuff_t *next_tvb;
|
||||
gboolean is_request;
|
||||
|
||||
CHECK_DISPLAY_AS_DATA(proto_sip, tvb, pinfo, tree);
|
||||
|
||||
|
@ -83,19 +81,15 @@ static void dissect_sip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
col_add_str(pinfo->fd, COL_PROTOCOL, "SIP");
|
||||
|
||||
offset = 0;
|
||||
eol = tvb_find_guint8(tvb, 0, tvb_length(tvb), '\r');
|
||||
if (eol < 0) goto bad;
|
||||
eol = tvb_get_nstringz0(tvb, 0, eol, buf);
|
||||
if (eol < 0) goto bad;
|
||||
eol += 2;
|
||||
if (tvb_get_guint8(tvb, eol) == '\n') {
|
||||
eol++;
|
||||
}
|
||||
is_request = sip_is_request(tvb, 0);
|
||||
eol = tvb_find_line_end(tvb, 0, -1, &next_offset);
|
||||
|
||||
if (check_col(pinfo->fd, COL_INFO))
|
||||
col_add_fstr(pinfo->fd, COL_INFO, "%s: %s",
|
||||
sip_is_request(buf) ? "Request" : "Status",
|
||||
sip_kill_version(buf, tmp));
|
||||
is_request ? "Request" : "Status",
|
||||
is_request ?
|
||||
tvb_format_text(tvb, 0, eol - strlen(" SIP/2.0")) :
|
||||
tvb_format_text(tvb, strlen("SIP/2.0 "), eol - strlen("SIP/2.0 ")));
|
||||
|
||||
col_set_writable(pinfo->fd, FALSE);
|
||||
|
||||
|
@ -106,23 +100,22 @@ static void dissect_sip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
ti = proto_tree_add_item(tree, proto_sip, tvb, 0, tvb_length(tvb), FALSE);
|
||||
sip_tree = proto_item_add_subtree(ti, ett_sip);
|
||||
|
||||
proto_tree_add_text(sip_tree, tvb, offset, eol, "%s-Line: %s",
|
||||
sip_is_request(buf) ? "Request" : "Status", buf);
|
||||
proto_tree_add_text(sip_tree, tvb, 0, next_offset, "%s-Line: %s",
|
||||
is_request ? "Request" : "Status",
|
||||
tvb_format_text(tvb, 0, eol));
|
||||
|
||||
offset = eol;
|
||||
offset = next_offset;
|
||||
msg_offset = sip_get_msg_offset(tvb, offset);
|
||||
if (msg_offset < 0) goto bad;
|
||||
th = proto_tree_add_item(sip_tree, hf_msg_hdr, tvb, offset, msg_offset - offset, FALSE);
|
||||
hdr_tree = proto_item_add_subtree(th, ett_sip_hdr);
|
||||
|
||||
|
||||
/* - 2 since we have a CRLF separating the message-body */
|
||||
while (msg_offset - 2 > offset) {
|
||||
int err;
|
||||
eol = tvb_find_guint8(tvb, offset, tvb_length_remaining(tvb, offset), '\r');
|
||||
err = tvb_get_nstringz0(tvb, offset, eol - offset, buf);
|
||||
if (err < 0) goto bad;
|
||||
proto_tree_add_text(hdr_tree, tvb, offset, strlen(buf) + 2, "%s", buf);
|
||||
offset = eol + 2;
|
||||
eol = tvb_find_line_end(tvb, offset, -1, &next_offset);
|
||||
proto_tree_add_text(hdr_tree, tvb, offset, next_offset - offset, "%s",
|
||||
tvb_format_text(tvb, offset, eol));
|
||||
offset = next_offset;
|
||||
}
|
||||
offset += 2; /* Skip the CRLF mentioned above */
|
||||
}
|
||||
|
@ -159,26 +152,12 @@ static gint sip_get_msg_offset(tvbuff_t *tvb, guint32 offset)
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* Remove the SIP-Version, 7 characters, from Request- or Status-Line.
|
||||
* Returns the modifed Line
|
||||
*/
|
||||
static guint8 *sip_kill_version(guint8 *orig, guint8 *killed)
|
||||
{
|
||||
if (sip_is_request(orig)) {
|
||||
strncpy(killed, orig, strlen(orig) - strlen("SIP/2.0"));
|
||||
killed[strlen(orig) - strlen("SIP/2.0")] = '\0';
|
||||
} else
|
||||
strcpy(killed, orig + strlen("SIP/2.0") + 1); /* + 1 to skip the space */
|
||||
|
||||
return killed;
|
||||
}
|
||||
|
||||
static int sip_is_request(const char *line)
|
||||
static int sip_is_request(tvbuff_t *tvb, guint32 offset)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 1; i < array_length(sip_methods); i++) {
|
||||
if (strncmp(line, sip_methods[i], strlen(sip_methods[i])) == 0)
|
||||
if (tvb_strneql(tvb, offset, sip_methods[i], strlen(sip_methods[i])) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue