static void dissect_dmx_chan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { col_set_str(pinfo->cinfo, COL_PROTOCOL, "DMX Channels"); col_clear(pinfo->cinfo, COL_INFO); if (tree != NULL) { static const char *chan_format[] = { "%2u%% ", "0x%02x ", "%3u " }; static const char *string_format[] = { "0x%03x: %s", "%3u: %s" }; emem_strbuf_t *chan_str = ep_strbuf_new_label(""); proto_item *item; guint16 length,r,c,row_count; guint8 v; unsigned offset = 0; proto_tree *ti = proto_tree_add_item(tree, proto_dmx_chan, tvb, offset, -1, ENC_NA); proto_tree *dmx_chan_tree = proto_item_add_subtree(ti, ett_dmx_chan); length = tvb_reported_length_remaining(tvb, offset); row_count = (length / global_disp_col_count) + ((length % global_disp_col_count) == 0 ? 0 : 1); for (r = 0; r < row_count;r++) { for (c = 0;(c < global_disp_col_count) && (((r * global_disp_col_count) + c) < length);c++) { if ((global_disp_col_count >= 2) && ((c % (global_disp_col_count / 2)) == 0)) { ep_strbuf_append(chan_str, " "); } v = tvb_get_guint8(tvb, (offset + (r * global_disp_col_count) + c)); if (global_disp_chan_val_type == 0) { v = (v * 100) / 255; if (v == 100) { ep_strbuf_append(chan_str, "FL "); } else { ep_strbuf_append_printf(chan_str, chan_format[global_disp_chan_val_type], v); } } else { ep_strbuf_append_printf(chan_str, chan_format[global_disp_chan_val_type], v); } } proto_tree_add_none_format(dmx_chan_tree, hf_dmx_chan_output_dmx_data, tvb, offset+(r * global_disp_col_count), c, string_format[global_disp_chan_nr_type], (r * global_disp_col_count) + 1, chan_str->str); } /* Add the real type hidden */ item = proto_tree_add_item(dmx_chan_tree, hf_dmx_chan_output_data_filter, tvb, offset, length, ENC_NA ); PROTO_ITEM_SET_HIDDEN(item); } }
/* * Preparse the message for the info column */ static emem_strbuf_t* get_column_info(tvbuff_t *tvb) { int byte_length; guint8 type_code; emem_strbuf_t *result_buf; int my_offset = 0; /* We've a full PDU: 8 bytes + pdu_packetlen bytes */ result_buf = ep_strbuf_new_label(""); my_offset += (4 + 4 + 1); /* skip Magic, Length, Version */ type_code = tvb_get_guint8(tvb, my_offset); byte_length = get_byte_length(type_code); my_offset++; if (byte_length == 4) { const gchar *symbol; guint32 hash; hash = tvb_get_ntohl(tvb, my_offset); symbol = try_val_to_str_ext(hash, gbl_symbols_vs_ext); if (symbol != NULL) { ep_strbuf_append_printf(result_buf, "%s()", symbol); } } return result_buf; }
/* * read a number and add it to tree */ static void read_number(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree, int asWhat, guint8 type_code) { int byteLength; read_type(offset, tvb, etch_tree); byteLength = get_byte_length(type_code); if (byteLength > 0) { proto_item *ti; const gchar *symbol = NULL; guint32 hash = 0; gbl_symbol_buffer = ep_strbuf_new_label(""); /* no symbol found yet */ if (byteLength == 4) { hash = tvb_get_ntohl(tvb, *offset); symbol = try_val_to_str_ext(hash, gbl_symbols_vs_ext); if(symbol != NULL) { asWhat = hf_etch_symbol; gbl_have_symbol = TRUE; ep_strbuf_append_printf(gbl_symbol_buffer,"%s",symbol); } } ti = proto_tree_add_item(etch_tree, asWhat, tvb, *offset, byteLength, ENC_BIG_ENDIAN); *offset += byteLength; if (symbol != NULL) { proto_item_append_text(ti, " (0x%08x) %s", hash, symbol); } } }
/** * dissect_messageid is a utility function which * calculates the ID of the message. * * @see dissect_packetid() * @see dissect_reliable_message_index_base() * @see dissect_content_length() * @see dissect_reliable_message_number() * @see dissect_payload() * @param buffer the buffer to the data * @param offset the offset where to start reading the data * @param tree the parent tree where the dissected data is going to be inserted * @return int returns the messageid * */ static int dissect_messageid(tvbuff_t *buffer, int *offset, proto_tree *tree, packet_info *pinfo, emem_strbuf_t* info_field) { gint messageid_length; guint8 messageid; messageid = tvb_get_bits8(buffer, (*offset) * 8, 8); switch(messageid) { case DISCONNECT: case DISCONNECTACK: case CONNECTSYN: case CONNECTSYNACK: case CONNECTACK: messageid_length = 4; break; default: messageid_length = 1; break; } proto_tree_add_bytes_format(tree, hf_knet_messageid, buffer, *offset, messageid_length, NULL, "Message ID: %s (%d)", val_to_str_const(messageid, packettypenames, "AppData or Malformed Message ID"), messageid); col_append_fstr(pinfo->cinfo, COL_INFO, "%s ", val_to_str_const(messageid, packettypenames, "AppData ")); *offset += messageid_length; ep_strbuf_append_printf(info_field, "Msg ID (%d) ", messageid); return messageid; }
/* This function converts a range_t to a (ep_alloc()-allocated) string. */ char * range_convert_range(range_t *range) { guint32 i; gboolean prepend_comma = FALSE; emem_strbuf_t *strbuf; strbuf=ep_strbuf_new(NULL); for (i=0; i < range->nranges; i++) { if (range->ranges[i].low == range->ranges[i].high) { ep_strbuf_append_printf(strbuf, "%s%u", prepend_comma?",":"", range->ranges[i].low); } else { ep_strbuf_append_printf(strbuf, "%s%u-%u", prepend_comma?",":"", range->ranges[i].low, range->ranges[i].high); } prepend_comma = TRUE; } return strbuf->str; }
static gint add_message(tvbuff_t * tvb, gint offset, proto_tree * tree, emem_strbuf_t * info) { guint16 descriptor_id, message_id; gint data_len; proto_item *msg; proto_tree *msg_tree; const gchar *descriptor; descriptor_id = tvb_get_ntohs(tvb, offset); message_id = tvb_get_ntohs(tvb, offset + 2); data_len = tvb_get_ntohs(tvb, offset + 4) * 2; /* Message subtree */ descriptor = val_to_str(descriptor_id, descriptors, "Unknown (%u)"); if (descriptor_id == ACK) msg = proto_tree_add_none_format(tree, hf_armagetronad_msg_subtree, tvb, offset, data_len + 6, "ACK %d messages", data_len / 2); else msg = proto_tree_add_none_format(tree, hf_armagetronad_msg_subtree, tvb, offset, data_len + 6, "Message 0x%04x [%s]", message_id, descriptor); msg_tree = proto_item_add_subtree(msg, ett_message); /* DescriptorID field */ proto_tree_add_item(msg_tree, hf_armagetronad_descriptor_id, tvb, offset, 2, ENC_BIG_ENDIAN); if (info) ep_strbuf_append_printf(info, "%s, ", descriptor); /* MessageID field */ proto_tree_add_item(msg_tree, hf_armagetronad_message_id, tvb, offset + 2, 2, ENC_BIG_ENDIAN); /* DataLen field */ proto_tree_add_item(msg_tree, hf_armagetronad_data_len, tvb, offset + 4, 2, ENC_BIG_ENDIAN); /* Data field */ add_message_data(tvb, offset + 6, data_len, msg_tree); return data_len + 6; }
static gchar * format_flags_string(guchar value, const gchar *array[]) { int i; guint bpos; emem_strbuf_t *buf; const char *sep = ""; buf = ep_strbuf_sized_new(MAX_FLAGS_LEN, MAX_FLAGS_LEN); for (i = 0; i < 8; i++) { bpos = 1 << i; if (value & bpos) { if (array[i][0]) { /* there is a string to emit... */ ep_strbuf_append_printf(buf, "%s%s", sep, array[i]); sep = ", "; } } } return buf->str; }
static const char * dissect_pim_addr(tvbuff_t *tvb, int offset, enum pimv2_addrtype at, int *advance) { emem_strbuf_t *strbuf; guint8 af; guint8 et; guint8 flags; guint8 mask_len; int len = 0; af = tvb_get_guint8(tvb, offset); if (af != AFNUM_INET && af != AFNUM_INET6) { /* * We don't handle the other formats, and addresses don't include * a length field, so we can't even show them as raw bytes. */ return NULL; } et = tvb_get_guint8(tvb, offset + 1); if (et != 0) { /* * The only defined encoding type is 0, for the native encoding; * again, as addresses don't include a length field, we can't * even show addresses with a different encoding type as raw * bytes. */ return NULL; } strbuf = ep_strbuf_new_label(NULL); switch (at) { case pimv2_unicast: switch (af) { case AFNUM_INET: len = 4; ep_strbuf_printf(strbuf, "%s", tvb_ip_to_str(tvb, offset + 2)); break; case AFNUM_INET6: len = 16; ep_strbuf_printf(strbuf, "%s", tvb_ip6_to_str(tvb, offset + 2)); break; } if (advance) *advance = 2 + len; break; case pimv2_group: mask_len = tvb_get_guint8(tvb, offset + 3); switch (af) { case AFNUM_INET: len = 4; ep_strbuf_printf(strbuf, "%s/%u", tvb_ip_to_str(tvb, offset + 4), mask_len); break; case AFNUM_INET6: len = 16; ep_strbuf_printf(strbuf, "%s/%u", tvb_ip6_to_str(tvb, offset + 4), mask_len); break; } if (advance) *advance = 4 + len; break; case pimv2_source: flags = tvb_get_guint8(tvb, offset + 2); mask_len = tvb_get_guint8(tvb, offset + 3); switch (af) { case AFNUM_INET: len = 4; ep_strbuf_printf(strbuf, "%s/%u", tvb_ip_to_str(tvb, offset + 4), mask_len); break; case AFNUM_INET6: len = 16; ep_strbuf_printf(strbuf, "%s/%u", tvb_ip6_to_str(tvb, offset + 4), mask_len); break; } if (flags) { ep_strbuf_append_printf(strbuf, " (%s%s%s)", flags & 0x04 ? "S" : "", flags & 0x02 ? "W" : "", flags & 0x01 ? "R" : ""); } if (advance) *advance = 4 + len; break; default: return NULL; } return strbuf->str; }
static void dissect_nstrace(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { proto_tree *ns_tree = NULL, *flagtree = NULL; proto_item *ti = NULL, *flagitem = NULL; struct nstr_phdr *pnstr = &(pinfo->pseudo_header->nstr); tvbuff_t *next_tvb_eth_client; guint8 offset; guint i, bpos; emem_strbuf_t *flags_strbuf = ep_strbuf_new_label("None"); const gchar *flags[] = {"FP", "FR", "DFD", "SRSS", "RSSH"}; gboolean first_flag = TRUE; guint8 flagoffset, flagval; guint8 src_vmname_len = 0, dst_vmname_len = 0; guint8 variable_ns_len = 0; if (pnstr->rec_type == NSPR_HEADER_VERSION205) { src_vmname_len = tvb_get_guint8(tvb,pnstr->src_vmname_len_offset); dst_vmname_len = tvb_get_guint8(tvb,pnstr->dst_vmname_len_offset); variable_ns_len = src_vmname_len + dst_vmname_len; pnstr->eth_offset += variable_ns_len; } ti = proto_tree_add_protocol_format(tree, proto_nstrace, tvb, 0, pnstr->eth_offset, "NetScaler Packet Trace"); ns_tree = proto_item_add_subtree(ti, ett_ns); proto_tree_add_item(ns_tree, hf_ns_dir, tvb, pnstr->dir_offset, pnstr->dir_len, ENC_LITTLE_ENDIAN); proto_tree_add_item(ns_tree, hf_ns_nicno, tvb, pnstr->nicno_offset, pnstr->nicno_len, ENC_LITTLE_ENDIAN); switch (pnstr->rec_type) { case NSPR_HEADER_VERSION205: if(src_vmname_len){ proto_tree_add_item(ns_tree,hf_ns_src_vm,tvb,pnstr->data_offset,src_vmname_len,ENC_LITTLE_ENDIAN); } if(dst_vmname_len){ proto_tree_add_item(ns_tree,hf_ns_dst_vm,tvb,pnstr->data_offset+src_vmname_len,dst_vmname_len,ENC_LITTLE_ENDIAN); } case NSPR_HEADER_VERSION204: flagoffset = pnstr->clflags_offset; flagval = tvb_get_guint8(tvb, flagoffset); for (i = 0; i < 5; i++) { bpos = 1 << i; if (flagval & bpos) { if (first_flag) { ep_strbuf_truncate(flags_strbuf, 0); } ep_strbuf_append_printf(flags_strbuf, "%s%s", first_flag ? "" : ", ", flags[i]); first_flag = FALSE; } } proto_tree_add_item(ns_tree, hf_ns_snode, tvb, pnstr->srcnodeid_offset, 2, ENC_LITTLE_ENDIAN); proto_tree_add_item(ns_tree, hf_ns_dnode, tvb, pnstr->destnodeid_offset, 2, ENC_LITTLE_ENDIAN); flagitem = proto_tree_add_uint_format(ns_tree, hf_ns_clflags, tvb, flagoffset, 1, flagval, "Cluster Flags: 0x%02x (%s)", flagval, flags_strbuf->str); flagtree = proto_item_add_subtree(flagitem, ett_ns_flags); proto_tree_add_boolean(flagtree, hf_ns_clflags_res, tvb, flagoffset, 1, flagval); proto_tree_add_boolean(flagtree, hf_ns_clflags_rssh, tvb, flagoffset, 1, flagval); proto_tree_add_boolean(flagtree, hf_ns_clflags_rss, tvb, flagoffset, 1, flagval); proto_tree_add_boolean(flagtree, hf_ns_clflags_dfd, tvb, flagoffset, 1, flagval); proto_tree_add_boolean(flagtree, hf_ns_clflags_fr, tvb, flagoffset, 1, flagval); proto_tree_add_boolean(flagtree, hf_ns_clflags_fp, tvb, flagoffset, 1, flagval); case NSPR_HEADER_VERSION203: proto_tree_add_item(ns_tree, hf_ns_coreid, tvb, pnstr->coreid_offset, 2, ENC_LITTLE_ENDIAN); /* fall through to next case */ case NSPR_HEADER_VERSION202: col_add_fstr(pinfo->cinfo, COL_8021Q_VLAN_ID, "%d", tvb_get_letohs(tvb, pnstr->vlantag_offset)); proto_tree_add_item(ns_tree, hf_ns_vlantag, tvb, pnstr->vlantag_offset, 2, ENC_LITTLE_ENDIAN); /* fall through to next case */ case NSPR_HEADER_VERSION201: proto_tree_add_item(ns_tree, hf_ns_pcbdevno, tvb, pnstr->pcb_offset, 4, ENC_LITTLE_ENDIAN); ti = proto_tree_add_item(ns_tree, hf_ns_devno, tvb, pnstr->pcb_offset, 4, ENC_LITTLE_ENDIAN); PROTO_ITEM_SET_HIDDEN(ti); proto_tree_add_item(ns_tree, hf_ns_l_pcbdevno, tvb, pnstr->l_pcb_offset, 4, ENC_LITTLE_ENDIAN); ti = proto_tree_add_item(ns_tree, hf_ns_devno, tvb, pnstr->l_pcb_offset, 4, ENC_LITTLE_ENDIAN); PROTO_ITEM_SET_HIDDEN(ti); break; default: break; } /* Dissect as Ethernet */ offset = pnstr->eth_offset; next_tvb_eth_client = tvb_new_subset_remaining(tvb, offset); call_dissector(eth_withoutfcs_handle, next_tvb_eth_client, pinfo, tree); }
static void dissect_fw1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { /* Set up structures needed to add the protocol subtree and manage it */ proto_item *ti; proto_tree *volatile fh_tree = NULL; char direction; char chain; char *interface_name; guint32 iface_len = 10; guint16 etype; emem_strbuf_t *header; int i; gboolean found; static const char fw1_header[] = "FW1 Monitor"; header = ep_strbuf_new_label(fw1_header); /* Make entries in Protocol column and Info column on summary display */ col_set_str(pinfo->cinfo, COL_PROTOCOL, "FW1"); col_clear(pinfo->cinfo, COL_INFO); /* g_snprintf(header, sizeof(header), fw1_header); */ /* fetch info to local variable */ direction = tvb_get_guint8(tvb, 0); if (!fw1_iflist_with_chain) chain = ' '; else chain = tvb_get_guint8(tvb, 1); if (fw1_with_uuid) iface_len = 6; interface_name=(char *)ep_alloc(iface_len+1); tvb_get_nstringz0(tvb, 2, iface_len+1, interface_name); /* Known interface name - if not, remember it */ found=FALSE; for (i=0; i<interface_anzahl; i++) { if ( strcmp(p_interfaces[i], interface_name) == 0 ) { found=TRUE; break; } } if (!found && interface_anzahl < MAX_INTERFACES) { p_interfaces[interface_anzahl] = se_strdup(interface_name); interface_anzahl++; } /* display all interfaces always in the same order */ for (i=0; i<interface_anzahl; i++) { if ( strcmp(p_interfaces[i], interface_name) == 0 ) { ep_strbuf_append_printf(header, " %c%c %s %c%c", direction == 'i' ? 'i' : (direction == 'O' ? 'O' : ' '), (direction == 'i' || direction == 'O') ? chain : ' ', p_interfaces[i], direction == 'I' ? 'I' : (direction == 'o' ? 'o' : ' '), (direction == 'I' || direction == 'o') ? chain : ' ' ); } else { ep_strbuf_append_printf(header, " %s ", p_interfaces[i]); } } col_add_str(pinfo->cinfo, COL_IF_DIR, header->str + sizeof(fw1_header) + 1); if (tree) { if (!fw1_summary_in_tree) /* Do not show the summary in Protocol Tree */ ti = proto_tree_add_protocol_format(tree, proto_fw1, tvb, 0, ETH_HEADER_SIZE, "%s", fw1_header); else ti = proto_tree_add_protocol_format(tree, proto_fw1, tvb, 0, ETH_HEADER_SIZE, "%s", header->str); /* create display subtree for the protocol */ fh_tree = proto_item_add_subtree(ti, ett_fw1); proto_tree_add_item(fh_tree, hf_fw1_direction, tvb, 0, 1, ENC_ASCII|ENC_NA); if (fw1_iflist_with_chain) proto_tree_add_item(fh_tree, hf_fw1_chain, tvb, 1, 1, ENC_ASCII|ENC_NA); proto_tree_add_item(fh_tree, hf_fw1_interface, tvb, 2, iface_len, ENC_ASCII|ENC_NA); if (fw1_with_uuid) proto_tree_add_item(fh_tree, hf_fw1_uuid, tvb, 8, 4, ENC_BIG_ENDIAN); } etype = tvb_get_ntohs(tvb, 12); ethertype(etype, tvb, ETH_HEADER_SIZE, pinfo, tree, fh_tree, hf_fw1_type, hf_fw1_trailer, 0); }