static void lbmtcp_order_key(lbmtcp_transport_t * transport) { gboolean swap = FALSE; int compare; /* Order the key so that addr1:port1 <= addr2:port2 */ compare = cmp_address(&(transport->addr1), &(transport->addr2)); if (compare > 0) { swap = TRUE; } else if (compare == 0) { if (transport->port1 > transport->port2) { swap = TRUE; } } if (swap) { address addr; guint16 port; copy_address_shallow(&addr, &(transport->addr1)); copy_address_shallow(&(transport->addr2), &(transport->addr1)); copy_address_shallow(&(transport->addr1), &addr); port = transport->port2; transport->port2 = transport->port1; transport->port1 = port; } }
static void dissect_ap1394(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { proto_item *ti; proto_tree *fh_tree = NULL; guint16 etype; tvbuff_t *next_tvb; col_set_str(pinfo->cinfo, COL_PROTOCOL, "IP/IEEE1394"); col_clear(pinfo->cinfo, COL_INFO); set_address_tvb(&pinfo->dl_src, AT_EUI64, 8, tvb, 8); copy_address_shallow(&pinfo->src, &pinfo->dl_src); set_address_tvb(&pinfo->dl_dst, AT_EUI64, 8, tvb, 0); copy_address_shallow(&pinfo->dst, &pinfo->dl_dst); if (tree) { ti = proto_tree_add_protocol_format(tree, proto_ap1394, tvb, 0, 18, "Apple IP-over-IEEE 1394, Src: %s, Dst: %s", address_to_str(wmem_packet_scope(), &pinfo->src), address_to_str(wmem_packet_scope(), &pinfo->dst)); fh_tree = proto_item_add_subtree(ti, ett_ap1394); proto_tree_add_item(fh_tree, hf_ap1394_dst, tvb, 0, 8, ENC_NA); proto_tree_add_item(fh_tree, hf_ap1394_src, tvb, 8, 8, ENC_NA); } etype = tvb_get_ntohs(tvb, 16); proto_tree_add_uint(fh_tree, hf_ap1394_type, tvb, 16, 2, etype); next_tvb = tvb_new_subset_remaining(tvb, 18); if (!dissector_try_uint(ethertype_subdissector_table, etype, next_tvb, pinfo, tree)) call_dissector(data_handle, next_tvb, pinfo, tree); }
static void dissect_redirecttlv(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset) { proto_tree *meta_data_tree, *meta_data_ilv_tree, *redirect_data_tree; gint start_offset; gint length_meta, length_ilv, length_redirect; proto_item *ti; address src_addr, src_net_addr; address dst_addr, dst_net_addr; copy_address_shallow(&src_addr, &pinfo->src); copy_address_shallow(&src_net_addr, &pinfo->net_src); copy_address_shallow(&dst_addr, &pinfo->dst); copy_address_shallow(&dst_net_addr, &pinfo->net_dst); meta_data_tree = proto_tree_add_subtree(tree, tvb, offset, TLV_TL_LENGTH, ett_forces_redirect_tlv_meta_data_tlv, &ti, "Meta Data TLV"); proto_tree_add_item(meta_data_tree, hf_forces_redirect_tlv_meta_data_tlv_type, tvb, offset, 2, ENC_BIG_ENDIAN); length_meta = tvb_get_ntohs(tvb, offset+2); proto_tree_add_uint(meta_data_tree, hf_forces_redirect_tlv_meta_data_tlv_length, tvb, offset+2, 2, length_meta); proto_item_set_len(ti, length_meta); start_offset = offset; while ((tvb_reported_length_remaining(tvb, offset) >= 8) && (start_offset+length_meta > offset)) { meta_data_ilv_tree = proto_tree_add_subtree(tree, tvb, offset, TLV_TL_LENGTH, ett_forces_redirect_tlv_meta_data_tlv_meta_data_ilv, &ti, "Meta Data ILV"); proto_tree_add_item(meta_data_ilv_tree, hf_forces_redirect_tlv_meta_data_tlv_meta_data_ilv_id, tvb, offset+8, 4, ENC_BIG_ENDIAN); length_ilv = tvb_get_ntohl(tvb, offset+12); proto_tree_add_uint(meta_data_ilv_tree, hf_forces_redirect_tlv_meta_data_tlv_meta_data_ilv_length, tvb, offset+12, 4, length_ilv); offset += 8; if (length_ilv > 0) { proto_tree_add_item(meta_data_ilv_tree, hf_forces_redirect_tlv_meta_data_tlv_meta_data_ilv, tvb, offset, length_ilv, ENC_NA); if (offset + length_ilv > offset) { offset += length_ilv; } } proto_item_set_len(ti, length_ilv + 8); } if (tvb_reported_length_remaining(tvb, offset) > 0) { redirect_data_tree = proto_tree_add_subtree(tree, tvb, offset, TLV_TL_LENGTH, ett_forces_redirect_tlv_redirect_data_tlv, &ti, "Redirect Data TLV"); proto_tree_add_item(redirect_data_tree, hf_forces_redirect_tlv_redirect_data_tlv_type, tvb, offset, 2, ENC_BIG_ENDIAN); length_redirect = tvb_get_ntohs(tvb, offset+2); proto_tree_add_uint(redirect_data_tree, hf_forces_redirect_tlv_redirect_data_tlv_length, tvb, offset+2, 2, length_redirect); if (tvb_reported_length_remaining(tvb, offset) < length_redirect) { expert_add_info_format(pinfo, ti, &ei_forces_redirect_tlv_redirect_data_tlv_length, "Bogus: Redirect Data TLV length (%u bytes) is wrong", length_redirect); } else if (length_redirect < TLV_TL_LENGTH + MIN_IP_HEADER_LENGTH) { expert_add_info_format(pinfo, ti, &ei_forces_redirect_tlv_redirect_data_tlv_length, "Bogus: Redirect Data TLV length (%u bytes) not big enough for IP layer", length_redirect); } else { tvbuff_t *next_tvb; next_tvb = tvb_new_subset_length(tvb, offset+4, length_redirect-TLV_TL_LENGTH); call_dissector(ip_handle, next_tvb, pinfo, redirect_data_tree); /* Restore IP info */ copy_address_shallow(&pinfo->src, &src_addr); copy_address_shallow(&pinfo->net_src, &src_net_addr); copy_address_shallow(&pinfo->dst, &dst_addr); copy_address_shallow(&pinfo->net_dst, &dst_net_addr); } } }
void add_hostlist_table_data(conv_hash_t *ch, const address *addr, guint32 port, gboolean sender, int num_frames, int num_bytes, hostlist_dissector_info_t *host_info, port_type port_type_val) { hostlist_talker_t *talker=NULL; int talker_idx=0; /* XXX should be optimized to allocate n extra entries at a time instead of just one */ /* if we don't have any entries at all yet */ if(ch->conv_array==NULL){ ch->conv_array=g_array_sized_new(FALSE, FALSE, sizeof(hostlist_talker_t), 10000); ch->hashtable = g_hash_table_new_full(host_hash, host_match, /* key_equal_func */ g_free, /* key_destroy_func */ NULL); /* value_destroy_func */ } else { /* try to find it among the existing known conversations */ host_key_t existing_key; gpointer talker_idx_hash_val; copy_address_shallow(&existing_key.myaddress, addr); existing_key.port = port; if (g_hash_table_lookup_extended(ch->hashtable, &existing_key, NULL, &talker_idx_hash_val)) { talker = &g_array_index(ch->conv_array, hostlist_talker_t, GPOINTER_TO_UINT(talker_idx_hash_val)); } } /* if we still don't know what talker this is it has to be a new one and we have to allocate it and append it to the end of the list */ if(talker==NULL){ host_key_t *new_key; hostlist_talker_t host; copy_address(&host.myaddress, addr); host.dissector_info = host_info; host.ptype=port_type_val; host.port=port; host.rx_frames=0; host.tx_frames=0; host.rx_bytes=0; host.tx_bytes=0; host.modified = TRUE; g_array_append_val(ch->conv_array, host); talker_idx= ch->conv_array->len - 1; talker=&g_array_index(ch->conv_array, hostlist_talker_t, talker_idx); /* hl->hosts address is not a constant but address.data is */ new_key = g_new(host_key_t,1); set_address(&new_key->myaddress, talker->myaddress.type, talker->myaddress.len, talker->myaddress.data); new_key->port = port; g_hash_table_insert(ch->hashtable, new_key, GUINT_TO_POINTER(talker_idx)); } /* if this is a new talker we need to initialize the struct */ talker->modified = TRUE; /* update the talker struct */ if( sender ){ talker->tx_frames+=num_frames; talker->tx_bytes+=num_bytes; } else { talker->rx_frames+=num_frames; talker->rx_bytes+=num_bytes; } }