* Routines for yahoo messenger packet dissection
* Copyright 1999, Nathan Neulinger <nneul@umr.edu>
*
- * $Id: packet-yhoo.c,v 1.6 2000/05/05 09:32:06 guy Exp $
+ * $Id: packet-yhoo.c,v 1.15 2001/04/23 04:29:54 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
};
static gboolean
-dissect_yhoo(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
+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)) ) {
+ 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;
}
- if (memcmp(&pd[offset], "YPNS", 4) != 0 &&
- memcmp(&pd[offset], "YHOO", 4) != 0) {
+ length = tvb_length(tvb);
+
+ 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;
}
- pkt = (struct yahoo_rawpacket *) &pd[offset];
-
- if (check_col(fd, COL_PROTOCOL))
- col_add_str(fd, COL_PROTOCOL, "YHOO");
+ if (check_col(pinfo->fd, COL_PROTOCOL))
+ col_set_str(pinfo->fd, COL_PROTOCOL, "YHOO");
- if (check_col(fd, COL_INFO))
- col_add_fstr(fd, COL_INFO,
+ 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);
+ 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_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);
+ 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;
&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));
void
proto_reg_handoff_yhoo(void)
{
- heur_dissector_add("tcp", dissect_yhoo);
+ heur_dissector_add("tcp", dissect_yhoo, proto_yhoo);
}