WSLUA_METAMETHOD Dissector__tostring(lua_State* L) { /* Gets the Dissector's protocol short name. */ Dissector d = checkDissector(L,1); if (!d) return 0; lua_pushstring(L,dissector_handle_get_short_name(d)); WSLUA_RETURN(1); /* A string of the protocol's short name. */ }
/* * A callback function to changed a dissector_handle if matched * This is used when iterating a dissector table */ static void change_dissector_if_matched(gpointer item, gpointer user_data) { dissector_handle_t handle = (dissector_handle_t)item; lookup_entry_t * lookup = (lookup_entry_t *)user_data; if (strcmp(lookup->dissector_short_name, dissector_handle_get_short_name(handle)) == 0) { lookup->handle = handle; } }
static void decode_proto_add_to_list (const gchar *table_name, gpointer value, gpointer user_data) { struct decode_as_default_populate* populate = (struct decode_as_default_populate*)user_data; const gchar *proto_name; gint i; dissector_handle_t handle; handle = (dissector_handle_t)value; proto_name = dissector_handle_get_short_name(handle); i = dissector_handle_get_protocol_index(handle); if (i >= 0 && !proto_is_protocol_enabled(find_protocol_by_id(i))) return; populate->add_to_list(table_name, proto_name, value, populate->ui_element); }
static void dissect_tzsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { proto_tree *tzsp_tree = NULL; proto_item *ti = NULL; int pos = 0; tvbuff_t *next_tvb; guint16 encapsulation = 0; int wtap_encap; dissector_handle_t encap_dissector; const char *encap_name; const char *info; guint8 type; col_set_str(pinfo->cinfo, COL_PROTOCOL, "TZSP"); col_clear(pinfo->cinfo, COL_INFO); type = tvb_get_guint8(tvb, 1); /* Find the dissector. */ encapsulation = tvb_get_ntohs(tvb, 2); if (encapsulation != 0) { wtap_encap = tzsp_encap_to_wtap_encap(encapsulation); if ((wtap_encap != -1) && (encap_dissector = dissector_get_uint_handle(encap_dissector_table, wtap_encap))) { encap_name = dissector_handle_get_short_name(encap_dissector); } else { encap_name = "Unknown"; } info = encap_name; } else { wtap_encap = -1; encap_name = "Nothing"; info = val_to_str(type, tzsp_type, "Unknown (%u)"); } col_add_str(pinfo->cinfo, COL_INFO, info); if (tree) { /* Adding TZSP item and subtree */ ti = proto_tree_add_protocol_format(tree, proto_tzsp, tvb, 0, -1, "TZSP: %s: ", info); tzsp_tree = proto_item_add_subtree(ti, ett_tzsp); proto_tree_add_item (tzsp_tree, hf_tzsp_version, tvb, 0, 1, ENC_BIG_ENDIAN); proto_tree_add_uint (tzsp_tree, hf_tzsp_type, tvb, 1, 1, type); proto_tree_add_uint_format (tzsp_tree, hf_tzsp_encap, tvb, 2, 2, encapsulation, "Encapsulates: %s (%d)", encap_name, encapsulation); } /* * XXX - what about TZSP_CONFIG frames? * * The MIB at * * http://web.archive.org/web/20021221195733/http://www.networkchemistry.com/support/appnotes/SENSOR-MIB * * seems to indicate that you can configure the probe using SNMP; * does TZSP_CONFIG also support that? An old version of Kismet * included code to control a Network Chemistry WSP100 sensor: * * https://www.kismetwireless.net/code-old/svn/tags/kismet-2004-02-R1/wsp100source.cc * * and it used SNMP to configure the probe. */ if ((type != TZSP_NULL) && (type != TZSP_PORT)) { pos = add_option_info(tvb, 4, tzsp_tree, ti); if (tree) proto_item_set_end(ti, tvb, pos); next_tvb = tvb_new_subset_remaining(tvb, pos); if ((encapsulation != 0) && ((wtap_encap == -1) || !dissector_try_uint(encap_dissector_table, wtap_encap, next_tvb, pinfo, tree))) { col_set_str(pinfo->cinfo, COL_PROTOCOL, "UNKNOWN"); col_add_fstr(pinfo->cinfo, COL_INFO, "TZSP_ENCAP = %u", encapsulation); call_dissector(data_handle, next_tvb, pinfo, tree); } } }
/* * This routine creates one entry in the list of protocol dissector * that have been changed. It is called by the g_hash_foreach routine * once for each changed entry in a dissector table. * * @param table_name The table name in which this dissector is found. * * @param key A pointer to the key for this entry in the dissector * hash table. This is generally the numeric selector of the * protocol, i.e. the ethernet type code, IP port number, TCP port * number, etc. * * @param value A pointer to the value for this entry in the dissector * hash table. This is an opaque pointer that can only be handed back * to routine in the file packet.c * * @param user_data A pointer to the list in which this information * should be stored. */ static void decode_build_show_list (const gchar *table_name, ftenum_t selector_type, gpointer key, gpointer value, gpointer user_data) { dissector_handle_t current, initial; const gchar *current_proto_name, *initial_proto_name; gchar *selector_name; gchar string1[20]; da_entry_t *entry; entry = g_new(da_entry_t,1); g_assert(user_data); g_assert(value); current = dtbl_entry_get_handle((dtbl_entry_t *)value); if (current == NULL) current_proto_name = DECODE_AS_NONE; else current_proto_name = dissector_handle_get_short_name(current); initial = dtbl_entry_get_initial_handle((dtbl_entry_t *)value); if (initial == NULL) initial_proto_name = DECODE_AS_NONE; else initial_proto_name = dissector_handle_get_short_name(initial); switch (selector_type) { case FT_UINT8: case FT_UINT16: case FT_UINT24: case FT_UINT32: switch (get_dissector_table_param(table_name)) { case BASE_DEC: g_snprintf(string1, sizeof(string1), "%u", GPOINTER_TO_UINT(key)); break; case BASE_HEX: switch (get_dissector_table_selector_type(table_name)) { case FT_UINT8: g_snprintf(string1, sizeof(string1), "0x%02x", GPOINTER_TO_UINT(key)); break; case FT_UINT16: g_snprintf(string1, sizeof(string1), "0x%04x", GPOINTER_TO_UINT(key)); break; case FT_UINT24: g_snprintf(string1, sizeof(string1), "0x%06x", GPOINTER_TO_UINT(key)); break; case FT_UINT32: g_snprintf(string1, sizeof(string1), "0x%08x", GPOINTER_TO_UINT(key)); break; default: g_assert_not_reached(); break; } break; case BASE_OCT: g_snprintf(string1, sizeof(string1), "%#o", GPOINTER_TO_UINT(key)); break; } selector_name = string1; break; case FT_STRING: case FT_STRINGZ: case FT_UINT_STRING: case FT_STRINGZPAD: selector_name = (gchar *)key; break; default: g_assert_not_reached(); selector_name = NULL; break; } decode_add_to_show_list ( user_data, get_dissector_table_ui_name(table_name), selector_name, initial_proto_name, current_proto_name); entry->table = g_strdup(table_name); entry->selector = GPOINTER_TO_UINT(key); entry->initial = g_strdup(initial_proto_name); entry->current = g_strdup(current_proto_name); da_entries = g_slist_append(da_entries, entry); }
static void dissect_tzsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { proto_tree *tzsp_tree = NULL; proto_item *ti = NULL; int pos = 0; tvbuff_t *next_tvb; guint16 encapsulation = 0; int wtap_encap; dissector_handle_t encap_dissector; const char *encap_name; const char *info; guint8 type; col_set_str(pinfo->cinfo, COL_PROTOCOL, "TZSP"); col_clear(pinfo->cinfo, COL_INFO); type = tvb_get_guint8(tvb, 1); /* Find the dissector. */ encapsulation = tvb_get_ntohs(tvb, 2); if (encapsulation != 0) { wtap_encap = tzsp_encap_to_wtap_encap(encapsulation); if (wtap_encap != -1 && (encap_dissector = dissector_get_port_handle(encap_dissector_table, wtap_encap))) { encap_name = dissector_handle_get_short_name(encap_dissector); } else { encap_name = "Unknown"; } info = encap_name; } else { wtap_encap = -1; encap_name = "Nothing"; info = val_to_str(type, tzsp_type, "Unknown (%u)"); } col_add_str(pinfo->cinfo, COL_INFO, info); if (tree) { /* Adding TZSP item and subtree */ ti = proto_tree_add_protocol_format(tree, proto_tzsp, tvb, 0, -1, "TZSP: %s: ", info); tzsp_tree = proto_item_add_subtree(ti, ett_tzsp); proto_tree_add_item (tzsp_tree, hf_tzsp_version, tvb, 0, 1, FALSE); proto_tree_add_uint (tzsp_tree, hf_tzsp_type, tvb, 1, 1, type); proto_tree_add_uint_format (tzsp_tree, hf_tzsp_encap, tvb, 2, 2, encapsulation, "Encapsulates: %s (%d)", encap_name, encapsulation); } if (type != 4 && type != 5) { pos = add_option_info(tvb, 4, tzsp_tree, ti); if (tree) proto_item_set_end(ti, tvb, pos); next_tvb = tvb_new_subset_remaining(tvb, pos); if (encapsulation != 0 && (wtap_encap == -1 || !dissector_try_port(encap_dissector_table, wtap_encap, next_tvb, pinfo, tree))) { col_set_str(pinfo->cinfo, COL_PROTOCOL, "UNKNOWN"); if (check_col(pinfo->cinfo, COL_INFO)) col_add_fstr(pinfo->cinfo, COL_INFO, "TZSP_ENCAP = %u", encapsulation); call_dissector(data_handle, next_tvb, pinfo, tree); } } }