/* Code to actually dissect the packets */ static void dissect_mtp3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { void* pd_save; mtp3_tap_rec_t* tap_rec = ep_alloc0(sizeof(mtp3_tap_rec_t)); gint heuristic_standard; guint8 si; /* Set up structures needed to add the protocol subtree and manage it */ proto_item *mtp3_item = NULL, *gen_item; proto_tree *mtp3_tree = NULL; pref_mtp3_standard = mtp3_standard; mtp3_item = proto_tree_add_item(tree, proto_mtp3, tvb, 0, 0, ENC_NA); si = tvb_get_guint8(tvb, SIO_OFFSET) & SERVICE_INDICATOR_MASK; if (mtp3_heuristic_standard) { heuristic_standard = heur_mtp3_standard(tvb, pinfo, si); if (heuristic_standard == HEURISTIC_FAILED_STANDARD) { gen_item = proto_tree_add_text(tree, tvb, 0, 0, "Could not determine Heuristic using %s", val_to_str(mtp3_standard, mtp3_standard_vals, "unknown")); } else { gen_item = proto_tree_add_text(tree, tvb, 0, 0, "%s", val_to_str(heuristic_standard, mtp3_standard_vals, "unknown")); mtp3_standard = heuristic_standard; /* Register a frame-end routine to ensure mtp3_standard is set * back, even if an exception is thrown. */ register_frame_end_routine(reset_mtp3_standard); } PROTO_ITEM_SET_GENERATED(gen_item); } /* Make entries in Protocol column on summary display */ switch(mtp3_standard) { case ITU_STANDARD: col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3 (Int. ITU)"); proto_item_set_len(mtp3_item, ITU_HEADER_LENGTH); break; case ANSI_STANDARD: col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3 (ANSI)"); proto_item_set_len(mtp3_item, ANSI_HEADER_LENGTH); break; case CHINESE_ITU_STANDARD: col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3 (Chin. ITU)"); proto_item_set_len(mtp3_item, ANSI_HEADER_LENGTH); break; case JAPAN_STANDARD: col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3 (Japan)"); proto_item_set_len(mtp3_item, JAPAN_HEADER_LENGTH); break; }; if (tree) { /* create display subtree for the protocol */ mtp3_tree = proto_item_add_subtree(mtp3_item, ett_mtp3); } mtp3_addr_opc = ep_alloc0(sizeof(mtp3_addr_pc_t)); mtp3_addr_dpc = ep_alloc0(sizeof(mtp3_addr_pc_t)); /* Dissect the packet (even if !tree so can call sub-dissectors and update * the source and destination address columns) */ dissect_mtp3_sio(tvb, pinfo, mtp3_tree, &pd_save); dissect_mtp3_routing_label(tvb, pinfo, mtp3_tree); memcpy(&(tap_rec->addr_opc), mtp3_addr_opc, sizeof(mtp3_addr_pc_t)); memcpy(&(tap_rec->addr_dpc), mtp3_addr_dpc, sizeof(mtp3_addr_pc_t)); tap_rec->si_code = (tvb_get_guint8(tvb, SIO_OFFSET) & SERVICE_INDICATOR_MASK); tap_rec->size = tvb_length(tvb); tap_queue_packet(mtp3_tap, pinfo, tap_rec); dissect_mtp3_payload(tvb, pinfo, tree); pinfo->private_data = pd_save; mtp3_standard = pref_mtp3_standard; }
int dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree) { int consumed_bytes = tvb->length; lua_pinfo = pinfo; lua_tvb = tvb; lua_tree = g_malloc(sizeof(struct _wslua_treeitem)); lua_tree->tree = tree; lua_tree->item = proto_tree_add_text(tree,tvb,0,0,"lua fake item"); lua_tree->expired = FALSE; PROTO_ITEM_SET_HIDDEN(lua_tree->item); /* * almost equivalent to Lua: * dissectors[current_proto](tvb,pinfo,tree) */ lua_settop(L,0); lua_rawgeti(L, LUA_REGISTRYINDEX, lua_dissectors_table_ref); lua_pushstring(L, pinfo->current_proto); lua_gettable(L, -2); lua_remove(L,1); if (lua_isfunction(L,1)) { push_Tvb(L,tvb); push_Pinfo(L,pinfo); push_TreeItem(L,lua_tree); if ( lua_pcall(L,3,1,0) ) { const gchar* error = lua_tostring(L,-1); proto_item* pi = proto_tree_add_text(tree,tvb,0,0,"Lua Error: %s",error); expert_add_info_format(pinfo, pi, PI_UNDECODED, PI_ERROR ,"Lua Error"); } else { /* if the Lua dissector reported the consumed bytes, pass it to our caller */ if (lua_isnumber(L, -1)) { /* we got the consumed bytes or the missing bytes as a negative number */ consumed_bytes = (int) lua_tonumber(L, -1); lua_pop(L, 1); } } } else { proto_item* pi = proto_tree_add_text(tree,tvb,0,0,"Lua Error: did not find the %s dissector" " in the dissectors table",pinfo->current_proto); expert_add_info_format(pinfo, pi, PI_UNDECODED, PI_ERROR ,"Lua Error"); } register_frame_end_routine(lua_frame_end); lua_pinfo = NULL; lua_tree = NULL; lua_tvb = NULL; return consumed_bytes; }