From 2fe0fc5a1afbbd8218190736decbecec14582691 Mon Sep 17 00:00:00 2001 From: Michael Mann Date: Sun, 8 Nov 2015 19:30:18 -0500 Subject: Convert some TCP subdissectors to "new" style. Change-Id: I28ce51f3c06f78b85792bce4a13ef39eb75d7890 Reviewed-on: https://code.wireshark.org/review/11648 Petri-Dish: Michael Mann Reviewed-by: Michael Mann --- epan/dissectors/packet-bfcp.c | 127 +++++++++++++++++++++++------------------- 1 file changed, 69 insertions(+), 58 deletions(-) (limited to 'epan/dissectors/packet-bfcp.c') diff --git a/epan/dissectors/packet-bfcp.c b/epan/dissectors/packet-bfcp.c index 0747af43e0..8022e0d778 100644 --- a/epan/dissectors/packet-bfcp.c +++ b/epan/dissectors/packet-bfcp.c @@ -386,15 +386,54 @@ dissect_bfcp_attributes(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int return offset; } + +static gboolean +dissect_bfcp_heur_check(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) +{ + guint8 primitive; + guint8 first_byte; + const gchar *str; + + + /* Size of smallest BFCP packet: 12 octets */ + if (tvb_captured_length(tvb) < 12) + return FALSE; + + /* Check version and reserved bits in first byte */ + first_byte = tvb_get_guint8(tvb, 0); + + /* If first_byte of bfcp_packet is a combination of the + * version and the I bit. The value must be either 0x20 or 0x30 + * if the bit is set, otherwise it is not BFCP. + */ + if ((first_byte != 0x20) && (first_byte != 0x30)) + return FALSE; + + primitive = tvb_get_guint8(tvb, 1); + + if ((primitive < 1) || (primitive > 18)) + return FALSE; + + str = try_val_to_str(primitive, map_bfcp_primitive); + if (NULL == str) + return FALSE; + + return TRUE; +} + /* Code to actually dissect BFCP packets */ -static void -dissect_bfcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) +static int +dissect_bfcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) { int offset = 0; guint8 primitive; const gchar *str; gint bfcp_payload_length; - proto_tree *bfcp_tree = NULL; + proto_tree *bfcp_tree; + proto_item *ti; + + if (!dissect_bfcp_heur_check(tvb, pinfo, tree, data)) + return 0; primitive = tvb_get_guint8(tvb, 1); str = try_val_to_str(primitive, map_bfcp_primitive); @@ -403,11 +442,8 @@ dissect_bfcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) col_set_str(pinfo->cinfo, COL_PROTOCOL, "BFCP"); col_add_str(pinfo->cinfo, COL_INFO, str); - if (tree) { - proto_item *ti; - - ti = proto_tree_add_item(tree, proto_bfcp, tvb, 0, -1, ENC_NA); - bfcp_tree = proto_item_add_subtree(ti, ett_bfcp); + ti = proto_tree_add_item(tree, proto_bfcp, tvb, 0, -1, ENC_NA); + bfcp_tree = proto_item_add_subtree(ti, ett_bfcp); /* The following is the format of the common header. @@ -425,62 +461,37 @@ dissect_bfcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) */ - /* Add items to BFCP tree */ - proto_tree_add_item(bfcp_tree, hf_bfcp_version, tvb, offset, 1, ENC_BIG_ENDIAN); - proto_tree_add_item(bfcp_tree, hf_bfcp_hdr_r_bit, tvb, offset, 1, ENC_BIG_ENDIAN); - proto_tree_add_item(bfcp_tree, hf_bfcp_hdr_f_bit, tvb, offset, 1, ENC_BIG_ENDIAN); - offset++; - proto_tree_add_item(bfcp_tree, hf_bfcp_primitive, tvb, offset, 1, ENC_BIG_ENDIAN); - offset++; - proto_tree_add_item(bfcp_tree, hf_bfcp_payload_length, tvb, offset, 2, ENC_BIG_ENDIAN); - offset+=2; - proto_tree_add_item(bfcp_tree, hf_bfcp_conference_id, tvb, offset, 4, ENC_BIG_ENDIAN); - offset+=4; - proto_tree_add_item(bfcp_tree, hf_bfcp_transaction_id, tvb, offset, 2, ENC_BIG_ENDIAN); - offset+=2; - proto_tree_add_item(bfcp_tree, hf_bfcp_user_id, tvb, offset, 2, ENC_BIG_ENDIAN); - offset+=2; - - bfcp_payload_length = tvb_get_ntohs(tvb, - BFCP_OFFSET_PAYLOAD_LENGTH) * 4; - - /*offset = */dissect_bfcp_attributes(tvb, pinfo, bfcp_tree, offset, bfcp_payload_length); - - } /* if(tree) */ + /* Add items to BFCP tree */ + proto_tree_add_item(bfcp_tree, hf_bfcp_version, tvb, offset, 1, ENC_BIG_ENDIAN); + proto_tree_add_item(bfcp_tree, hf_bfcp_hdr_r_bit, tvb, offset, 1, ENC_BIG_ENDIAN); + proto_tree_add_item(bfcp_tree, hf_bfcp_hdr_f_bit, tvb, offset, 1, ENC_BIG_ENDIAN); + offset++; + proto_tree_add_item(bfcp_tree, hf_bfcp_primitive, tvb, offset, 1, ENC_BIG_ENDIAN); + offset++; + proto_tree_add_item(bfcp_tree, hf_bfcp_payload_length, tvb, offset, 2, ENC_BIG_ENDIAN); + offset+=2; + proto_tree_add_item(bfcp_tree, hf_bfcp_conference_id, tvb, offset, 4, ENC_BIG_ENDIAN); + offset+=4; + proto_tree_add_item(bfcp_tree, hf_bfcp_transaction_id, tvb, offset, 2, ENC_BIG_ENDIAN); + offset+=2; + proto_tree_add_item(bfcp_tree, hf_bfcp_user_id, tvb, offset, 2, ENC_BIG_ENDIAN); + offset+=2; + + bfcp_payload_length = tvb_get_ntohs(tvb, + BFCP_OFFSET_PAYLOAD_LENGTH) * 4; + + /*offset = */dissect_bfcp_attributes(tvb, pinfo, bfcp_tree, offset, bfcp_payload_length); + + return tvb_captured_length(tvb); } static gboolean dissect_bfcp_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) { - guint8 primitive; - guint8 first_byte; - const gchar *str; - - - /* Size of smallest BFCP packet: 12 octets */ - if (tvb_captured_length(tvb) < 12) - return FALSE; - - /* Check version and reserved bits in first byte */ - first_byte = tvb_get_guint8(tvb, 0); - - /* If first_byte of bfcp_packet is a combination of the - * version and the I bit. The value must be either 0x20 or 0x30 - * if the bit is set, otherwise it is not BFCP. - */ - if ((first_byte != 0x20) && (first_byte != 0x30)) - return FALSE; - - primitive = tvb_get_guint8(tvb, 1); - - if ((primitive < 1) || (primitive > 18)) - return FALSE; - - str = try_val_to_str(primitive, map_bfcp_primitive); - if (NULL == str) + if (!dissect_bfcp_heur_check(tvb, pinfo, tree, data)) return FALSE; - dissect_bfcp(tvb, pinfo, tree); + dissect_bfcp(tvb, pinfo, tree, data); return TRUE; } @@ -679,7 +690,7 @@ void proto_register_bfcp(void) proto_bfcp = proto_register_protocol("Binary Floor Control Protocol", "BFCP", "bfcp"); - bfcp_handle = register_dissector("bfcp", dissect_bfcp, proto_bfcp); + bfcp_handle = new_register_dissector("bfcp", dissect_bfcp, proto_bfcp); bfcp_module = prefs_register_protocol(proto_bfcp, proto_reg_handoff_bfcp); -- cgit v1.2.3