* Routines for yahoo messenger packet dissection
* Copyright 1999, Nathan Neulinger <nneul@umr.edu>
*
- * $Id: packet-yhoo.c,v 1.3 1999/10/20 16:36:07 gram Exp $
+ * $Id: packet-yhoo.c,v 1.16 2001/06/18 02:17:58 guy Exp $
*
* Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@unicom.net>
+ * By Gerald Combs <gerald@zing.org>
* Copyright 1998 Gerald Combs
*
* Copied from packet-tftp.c
static int hf_yhoo_nick2 = -1;
static int hf_yhoo_content = -1;
+static gint ett_yhoo = -1;
+
+#define TCP_PORT_YHOO 5050
+
static const value_string yhoo_service_vals[] = {
{YAHOO_SERVICE_LOGON, "Pager Logon"},
{YAHOO_SERVICE_LOGOFF, "Pager Logoff"},
{0, NULL}
};
-void
-dissect_yhoo(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
+static gboolean
+dissect_yhoo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
proto_tree *yhoo_tree, *ti;
- struct yahoo_rawpacket *pkt;
+ int offset = 0;
+ int length = 0;
+
+ if (!proto_is_protocol_enabled(proto_yhoo)) {
+ return FALSE;
+ }
+
+ if (pi.srcport != TCP_PORT_YHOO && pi.destport != TCP_PORT_YHOO) {
+ /* Not the Yahoo port - not a Yahoo Messenger packet. */
+ return FALSE;
+ }
/* get at least a full packet structure */
- if ( !BYTES_ARE_IN_FRAME(offset, sizeof(struct yahoo_rawpacket)) )
- return;
+ if ( !tvb_bytes_exist(tvb, 0, sizeof(struct yahoo_rawpacket)) ) {
+ /* Not enough data captured; maybe it is a Yahoo
+ Messenger packet, but it contains too little data to
+ tell. */
+ return FALSE;
+ }
- pkt = (struct yahoo_rawpacket *) &pd[offset];
-
- if (check_col(fd, COL_PROTOCOL))
- col_add_str(fd, COL_PROTOCOL, "YHOO");
+ length = tvb_length(tvb);
- if (check_col(fd, COL_INFO))
- col_add_fstr(fd, COL_INFO,
+ if (memcmp(tvb_get_ptr(tvb, offset, 4), "YPNS", 4) != 0 &&
+ memcmp(tvb_get_ptr(tvb, offset, 4), "YHOO", 4) != 0) {
+ /* Not a Yahoo Messenger packet. */
+ return FALSE;
+ }
+
+ if (check_col(pinfo->fd, COL_PROTOCOL))
+ col_set_str(pinfo->fd, COL_PROTOCOL, "YHOO");
+
+ offset = 0;
+ if (check_col(pinfo->fd, COL_INFO)) {
+ col_add_fstr(pinfo->fd, COL_INFO,
"%s: %s",
- ( strncmp(pkt->version, "YPNS", 4) == 0 ) ? "Request" : "Response",
- val_to_str(pletohl(pkt->service),
+ ( strncmp(tvb_get_ptr(tvb, offset + 0, 4), "YPNS", 4) == 0 ) ? "Request" : "Response",
+ val_to_str(tvb_get_letohl(tvb, offset + 12),
yhoo_service_vals, "Unknown Service: %u")
);
+ }
if (tree) {
- ti = proto_tree_add_item(tree, proto_yhoo, offset, END_OF_FRAME, NULL);
- yhoo_tree = proto_item_add_subtree(ti, ETT_YHOO);
-
- proto_tree_add_item(yhoo_tree, hf_yhoo_version,
- offset, 8, pkt->version);
- proto_tree_add_item(yhoo_tree, hf_yhoo_len,
- offset+8, 4, pletohl(pkt->len));
- proto_tree_add_item(yhoo_tree, hf_yhoo_service,
- offset+12, 4, pletohl(pkt->service));
- proto_tree_add_item(yhoo_tree, hf_yhoo_connection_id,
- offset+16, 4, pletohl(pkt->connection_id));
- proto_tree_add_item(yhoo_tree, hf_yhoo_magic_id,
- offset+20, 4, pletohl(pkt->magic_id));
- proto_tree_add_item(yhoo_tree, hf_yhoo_unknown1,
- offset+24, 4, pletohl(pkt->unknown1));
- proto_tree_add_item(yhoo_tree, hf_yhoo_msgtype,
- offset+28, 4, pletohl(pkt->msgtype));
- proto_tree_add_item(yhoo_tree, hf_yhoo_nick1,
- offset+32, 36, pkt->nick1);
- proto_tree_add_item(yhoo_tree, hf_yhoo_nick2,
- offset+68, 36, pkt->nick2);
- proto_tree_add_item(yhoo_tree, hf_yhoo_content,
- offset+104, END_OF_FRAME, pkt->content);
+ ti = proto_tree_add_item(tree, proto_yhoo, tvb, offset,
+ tvb_length_remaining(tvb, offset), FALSE);
+ yhoo_tree = proto_item_add_subtree(ti, ett_yhoo);
+
+ proto_tree_add_string(yhoo_tree, hf_yhoo_version, tvb,
+ offset, 8, tvb_get_ptr(tvb, offset, 8));
+ offset += 8;
+
+ proto_tree_add_uint(yhoo_tree, hf_yhoo_len, tvb,
+ offset, 4, tvb_get_letohl(tvb, offset));
+ offset += 4;
+
+ proto_tree_add_uint(yhoo_tree, hf_yhoo_service, tvb,
+ offset, 4, tvb_get_letohl(tvb, offset));
+ offset += 4;
+
+ proto_tree_add_uint(yhoo_tree, hf_yhoo_connection_id, tvb,
+ offset, 4, tvb_get_letohl(tvb, offset));
+ offset += 4;
+
+ proto_tree_add_uint(yhoo_tree, hf_yhoo_magic_id, tvb,
+ offset, 4, tvb_get_letohl(tvb, offset));
+ offset += 4;
+
+ proto_tree_add_uint(yhoo_tree, hf_yhoo_unknown1, tvb,
+ offset, 4, tvb_get_letohl(tvb, offset));
+ offset += 4;
+
+ proto_tree_add_uint(yhoo_tree, hf_yhoo_msgtype, tvb,
+ offset, 4, tvb_get_letohl(tvb, offset));
+ offset += 4;
+
+ proto_tree_add_string(yhoo_tree, hf_yhoo_nick1, tvb,
+ offset, 36, tvb_get_ptr(tvb, offset, 36));
+ offset += 36;
+
+ proto_tree_add_string(yhoo_tree, hf_yhoo_nick2, tvb,
+ offset, 36, tvb_get_ptr(tvb, offset, 36));
+ offset += 36;
+
+ proto_tree_add_string(yhoo_tree, hf_yhoo_content, tvb,
+ offset, length, tvb_get_ptr(tvb, offset, length-offset));
}
+
+ return TRUE;
}
void
static hf_register_info hf[] = {
{ &hf_yhoo_service, {
"Service Type", "yhoo.service", FT_UINT32, BASE_DEC,
- VALS(yhoo_service_vals), 0, "Service Type" }},
+ VALS(yhoo_service_vals), 0, "Service Type", HFILL }},
{ &hf_yhoo_msgtype, {
"Message Type", "yhoo.msgtype", FT_UINT32, BASE_DEC,
- VALS(yhoo_msgtype_vals), 0, "Message Type Flags" }},
+ VALS(yhoo_msgtype_vals), 0, "Message Type Flags", HFILL }},
{ &hf_yhoo_connection_id, {
"Connection ID", "yhoo.connection_id", FT_UINT32, BASE_HEX,
- NULL, 0, "Connection ID" }},
+ NULL, 0, "Connection ID", HFILL }},
{ &hf_yhoo_magic_id, {
"Magic ID", "yhoo.magic_id", FT_UINT32, BASE_HEX,
- NULL, 0, "Magic ID" }},
+ NULL, 0, "Magic ID", HFILL }},
{ &hf_yhoo_unknown1, {
"Unknown 1", "yhoo.unknown1", FT_UINT32, BASE_HEX,
- NULL, 0, "Unknown 1" }},
+ NULL, 0, "Unknown 1", HFILL }},
{ &hf_yhoo_len, {
"Packet Length", "yhoo.len", FT_UINT32, BASE_DEC,
- NULL, 0, "Packet Length" }},
+ NULL, 0, "Packet Length", HFILL }},
{ &hf_yhoo_nick1, {
"Real Nick (nick1)", "yhoo.nick1", FT_STRING, 0,
- NULL, 0, "Real Nick (nick1)" }},
+ NULL, 0, "Real Nick (nick1)", HFILL }},
{ &hf_yhoo_nick2, {
"Active Nick (nick2)", "yhoo.nick2", FT_STRING, 0,
- NULL, 0, "Active Nick (nick2)" }},
+ NULL, 0, "Active Nick (nick2)", HFILL }},
{ &hf_yhoo_content, {
"Content", "yhoo.content", FT_STRING, 0,
- NULL, 0, "Data portion of the packet" }},
+ NULL, 0, "Data portion of the packet", HFILL }},
{ &hf_yhoo_version, {
"Version", "yhoo.version", FT_STRING, 0,
- NULL, 0, "Packet version identifier" }},
+ NULL, 0, "Packet version identifier", HFILL }},
};
+ static gint *ett[] = {
+ &ett_yhoo,
+ };
- proto_yhoo = proto_register_protocol("Yahoo Messenger Protocol", "yhoo");
+ proto_yhoo = proto_register_protocol("Yahoo Messenger Protocol",
+ "YHOO", "yhoo");
proto_register_field_array(proto_yhoo, hf, array_length(hf));
+
+ proto_register_subtree_array(ett, array_length(ett));
+}
+
+void
+proto_reg_handoff_yhoo(void)
+{
+ heur_dissector_add("tcp", dissect_yhoo, proto_yhoo);
}