/* A helper function that calls find_conversation() and, if a conversation is * not found, calls conversation_new(). * The frame number and addresses are taken from pinfo. * No options are used, though we could extend this API to include an options * parameter. */ conversation_t * find_or_create_conversation(packet_info *pinfo) { conversation_t *conv=NULL; DPRINT(("called for frame #%d: %s:%d -> %s:%d (ptype=%d)", pinfo->fd->num, address_to_str(wmem_packet_scope(), &pinfo->src), pinfo->srcport, address_to_str(wmem_packet_scope(), &pinfo->dst), pinfo->destport, pinfo->ptype)); DINDENT(); /* Have we seen this conversation before? */ if((conv = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype, pinfo->srcport, pinfo->destport, 0)) != NULL) { DPRINT(("found previous conversation for frame #%d (last_frame=%d)", pinfo->fd->num, conv->last_frame)); if (pinfo->fd->num > conv->last_frame) { conv->last_frame = pinfo->fd->num; } } else { /* No, this is a new conversation. */ DPRINT(("did not find previous conversation for frame #%d", pinfo->fd->num)); DINDENT(); conv = conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype, pinfo->srcport, pinfo->destport, 0); DENDENT(); } DENDENT(); return conv; }
/* * Given two address/port pairs for a packet, create a new conversation * to contain packets between those address/port pairs. * * The options field is used to specify whether the address 2 value * and/or port 2 value are not given and any value is acceptable * when searching for this conversation. */ conversation_t * conversation_new(const guint32 setup_frame, const address *addr1, const address *addr2, const port_type ptype, const guint32 port1, const guint32 port2, const guint options) { /* DISSECTOR_ASSERT(!(options | CONVERSATION_TEMPLATE) || ((options | (NO_ADDR2 | NO_PORT2 | NO_PORT2_FORCE))) && "A conversation template may not be constructed without wildcard options"); */ GHashTable* hashtable; conversation_t *conversation=NULL; conversation_key *new_key; DPRINT(("creating conversation for frame #%d: %s:%d -> %s:%d (ptype=%d)", setup_frame, address_to_str(wmem_packet_scope(), addr1), port1, address_to_str(wmem_packet_scope(), addr2), port2, ptype)); if (options & NO_ADDR2) { if (options & (NO_PORT2|NO_PORT2_FORCE)) { hashtable = conversation_hashtable_no_addr2_or_port2; } else { hashtable = conversation_hashtable_no_addr2; } } else { if (options & (NO_PORT2|NO_PORT2_FORCE)) { hashtable = conversation_hashtable_no_port2; } else { hashtable = conversation_hashtable_exact; } } new_key = wmem_new(wmem_file_scope(), struct conversation_key); new_key->next = conversation_keys; conversation_keys = new_key; copy_address_wmem(wmem_file_scope(), &new_key->addr1, addr1); copy_address_wmem(wmem_file_scope(), &new_key->addr2, addr2); new_key->ptype = ptype; new_key->port1 = port1; new_key->port2 = port2; conversation = wmem_new(wmem_file_scope(), conversation_t); memset(conversation, 0, sizeof(conversation_t)); conversation->index = new_index; conversation->setup_frame = conversation->last_frame = setup_frame; conversation->data_list = NULL; conversation->dissector_tree = wmem_tree_new(wmem_file_scope()); /* set the options and key pointer */ conversation->options = options; conversation->key_ptr = new_key; new_index++; DINDENT(); conversation_insert_into_hashtable(hashtable, conversation); DENDENT(); return conversation; }
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 const gchar *gen_olc_key(guint16 lc_num, address *dst_addr, address *src_addr) { return wmem_strdup_printf(wmem_packet_scope(), "%s/%s/%u", address_to_str(wmem_packet_scope(), dst_addr), address_to_str(wmem_packet_scope(), src_addr), lc_num); }
static void tacplus_print_key_entry( gpointer data, gpointer user_data ) { tacplus_key_entry *tacplus_data=(tacplus_key_entry *)data; if( user_data ) { printf("%s:%s=%s\n", address_to_str( tacplus_data->s ), address_to_str( tacplus_data->c ), tacplus_data->k ); } else { printf("%s:%s\n", address_to_str( tacplus_data->s ), address_to_str( tacplus_data->c ) ); } }
/* * Set the address 2 value in a key. Remove the original from * table, update the options and port values, insert the updated key. */ void conversation_set_addr2(conversation_t *conv, const address *addr) { char* addr_str; DISSECTOR_ASSERT_HINT(!(conv->options & CONVERSATION_TEMPLATE), "Use the conversation_create_from_template function when the CONVERSATION_TEMPLATE bit is set in the options mask"); addr_str = address_to_str(NULL, addr); DPRINT(("called for addr=%s", addr_str)); wmem_free(NULL, addr_str); /* * If the address 2 value is not wildcarded, don't set it. */ if (!(conv->options & NO_ADDR2)) return; DINDENT(); if (conv->options & NO_PORT2) { conversation_remove_from_hashtable(conversation_hashtable_no_addr2_or_port2, conv); } else { conversation_remove_from_hashtable(conversation_hashtable_no_port2, conv); } conv->options &= ~NO_ADDR2; copy_address_wmem(wmem_file_scope(), &conv->key_ptr->addr2, addr); if (conv->options & NO_PORT2) { conversation_insert_into_hashtable(conversation_hashtable_no_port2, conv); } else { conversation_insert_into_hashtable(conversation_hashtable_exact, conv); } DENDENT(); }
char *get_hostlist_filter(hostlist_talker_t *host) { char *sport, *src_addr; char *str; sport = ct_port_to_str(host->ptype, host->port); src_addr = address_to_str(NULL, &host->myaddress); if (host->myaddress.type == AT_STRINGZ || host->myaddress.type == AT_USB) { char *new_addr; new_addr = wmem_strdup_printf(NULL, "\"%s\"", src_addr); wmem_free(NULL, src_addr); src_addr = new_addr; } str = g_strdup_printf("%s==%s%s%s%s%s", hostlist_get_filter_name(host, CONV_FT_ANY_ADDRESS), src_addr, sport?" && ":"", sport?hostlist_get_filter_name(host, CONV_FT_ANY_PORT):"", sport?"==":"", sport?sport:""); g_free(sport); wmem_free(NULL, src_addr); return str; }
static void tacplus_print_key_entry( gpointer data, gpointer user_data ) { tacplus_key_entry *tacplus_data=(tacplus_key_entry *)data; gchar *s_str, *c_str; s_str = address_to_str( NULL, tacplus_data->s ); c_str = address_to_str( NULL, tacplus_data->c ); if( user_data ) { printf("%s:%s=%s\n", s_str, c_str, tacplus_data->k ); } else { printf("%s:%s\n", s_str, c_str ); } wmem_free(NULL, s_str); wmem_free(NULL, c_str); }
char *get_conversation_address(wmem_allocator_t *allocator, address *addr, gboolean resolve_names) { if (resolve_names) { return address_to_display(allocator, addr); } else { return address_to_str(allocator, addr); } }
void delete_conversations (void) { GList *item = conversations; conversation_t *conv = NULL; while (item) { conv = item->data; g_my_debug ("Removing conversation %s:%d-%s:%d %s", address_to_str (&conv->src_address), conv->src_port, address_to_str (&conv->dst_address), conv->dst_port, conv->data); g_free (conv->data); g_free (conv); item = item->next; n_conversations--; } g_list_free (conversations); conversations = NULL; } /* delete_conversations */
const QString address_to_qstring(const _address *address, bool enclose) { QString address_qstr = QString(); if (address) { if (enclose && address->type == AT_IPv6) address_qstr += "["; gchar *address_gchar_p = address_to_str(NULL, address); address_qstr += address_gchar_p; wmem_free(NULL, address_gchar_p); if (enclose && address->type == AT_IPv6) address_qstr += "]"; } return address_qstr; }
char * lbttcp_transport_source_string(const address * source_address, guint16 source_port, guint32 session_id) { char * bufptr = NULL; if (session_id == 0) { bufptr = wmem_strdup_printf(wmem_file_scope(), "TCP:%s:%" G_GUINT16_FORMAT, address_to_str(wmem_packet_scope(), source_address), source_port); } else { bufptr = wmem_strdup_printf(wmem_file_scope(), "TCP:%s:%" G_GUINT16_FORMAT ":%08x", address_to_str(wmem_packet_scope(), source_address), source_port, session_id); } return (bufptr); }
QString LBMStreamEntry::formatEndpoint(const packet_info * pinfo, const lbm_uim_stream_endpoint_t * endpoint) { if (endpoint->type == lbm_uim_instance_stream) { return QString(bytes_to_str(pinfo->pool, endpoint->stream_info.ctxinst.ctxinst, sizeof(endpoint->stream_info.ctxinst.ctxinst))); } else { return QString("%1:%2:%3") .arg(endpoint->stream_info.dest.domain) .arg(address_to_str(pinfo->pool, &(endpoint->stream_info.dest.addr))) .arg(endpoint->stream_info.dest.port); } }
static const char * format_address(const unsigned char *prefix) { address addr; if (prefix == NULL) return "corrupt"; else if (memcmp(prefix, v4prefix, 12) == 0) { addr.type = AT_IPv4; addr.len = 4; addr.data = prefix + 12; return address_to_str(wmem_packet_scope(), &addr); } else { addr.type = AT_IPv6; addr.len = 16; addr.data = prefix; return address_to_str(wmem_packet_scope(), &addr); } }
/* removes all conversations with the specified addresses */ void delete_conversation_link(address_t * src_address, address_t * dst_address) { GList *item; if (!src_address || !dst_address) { g_my_critical("NULL ptr in delete_conversation_link"); return; } while ( (item = find_conversation_ptr(src_address, dst_address, 0, 0)) ) { conversation_t *conv = NULL; conv = item->data; g_my_debug ("Removing conversation %s:%d-%s:%d %s", address_to_str (&conv->src_address), conv->src_port, address_to_str (&conv->dst_address), conv->dst_port, conv->data); g_free (conv->data); g_free (conv); conversations = g_list_delete_link(conversations, item); n_conversations--; } }
static gchar * lbmc_stream_dlg_format_endpoint_ep(const lbm_uim_stream_endpoint_t * endpoint) { gchar * buf = NULL; if (endpoint->type == lbm_uim_instance_stream) { buf = bytes_to_ep_str(endpoint->stream_info.ctxinst.ctxinst, sizeof(endpoint->stream_info.ctxinst.ctxinst)); } else { buf = wmem_strdup_printf(wmem_packet_scope(), "%" G_GUINT32_FORMAT ":%s:%" G_GUINT16_FORMAT, endpoint->stream_info.dest.domain, address_to_str(wmem_packet_scope(), &(endpoint->stream_info.dest.addr)), endpoint->stream_info.dest.port); } return (buf); }
static int dissect_mount_dirpath_call(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data) { const char *mountpoint=NULL; int offset = 0; if((!pinfo->fd->visited) && nfs_file_name_snooping){ rpc_call_info_value *civ=(rpc_call_info_value *)data; if(civ->request && (civ->proc==1)){ guint32 len_field; len_field = tvb_get_ntohl(tvb, offset); if (len_field < ITEM_LABEL_LENGTH) { gchar *name, *ptr; int addr_len, name_len; name = address_to_str(wmem_packet_scope(), &pinfo->dst); addr_len = (int)strlen(name); /* IP address, colon, path, terminating 0 */ name_len = addr_len + 1 + len_field + 1; name = (gchar *)wmem_realloc(wmem_packet_scope(), (void *)name, name_len); ptr = name + addr_len; *ptr++ = ':'; tvb_memcpy(tvb, ptr, offset+4, len_field); ptr += len_field; *ptr = 0; nfs_name_snoop_add_name(civ->xid, tvb, -1, name_len, 0, 0, name); } } } offset = dissect_rpc_string(tvb,tree,hf_mount_path,offset,&mountpoint); col_append_fstr(pinfo->cinfo, COL_INFO," %s", mountpoint); return offset; }
static int dissect_mount_dirpath_call(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data) { const char *mountpoint=NULL; int offset = 0; if((!pinfo->fd->flags.visited) && nfs_file_name_snooping){ rpc_call_info_value *civ=(rpc_call_info_value *)data; if(civ->request && (civ->proc==1)){ const gchar *host; unsigned char *name; guint32 len; unsigned char *ptr; host=address_to_str(wmem_packet_scope(), &pinfo->dst); len=tvb_get_ntohl(tvb, offset); if (len >= ITEM_LABEL_LENGTH) THROW(ReportedBoundsError); name=(unsigned char *)g_malloc(strlen(host)+1+len+1+200); ptr=name; memcpy(ptr, host, strlen(host)); ptr+=strlen(host); *ptr++=':'; tvb_memcpy(tvb, ptr, offset+4, len); ptr+=len; *ptr=0; nfs_name_snoop_add_name(civ->xid, tvb, -1, (gint)strlen(name), 0, 0, name); } } offset = dissect_rpc_string(tvb,tree,hf_mount_path,offset,&mountpoint); col_append_fstr(pinfo->cinfo, COL_INFO," %s", mountpoint); return offset; }
void add_conversation (address_t * src_address, address_t * dst_address, guint16 src_port, guint16 dst_port, const gchar * data) { conversation_t *conv = NULL; const gchar *old_data = NULL; if (!src_address || !dst_address) { g_my_critical("NULL ptr in add_conversation"); return; } /* Make sure there is not one such conversation */ if ((old_data = find_conversation (src_address, dst_address, src_port, dst_port))) { if (!strcmp (old_data, data)) g_my_critical ("Conflicting conversations %s:%d-%s:%d in add_conversation", address_to_str (src_address), src_port, address_to_str (dst_address), dst_port); else g_my_debug ("Conversation %s:%d-%s:%d %s already exists in add_conversation", address_to_str (src_address), src_port, address_to_str (dst_address), dst_port, data); return; } g_my_debug ("Adding new conversation %s:%d-%s:%d %s", address_to_str (src_address), src_port, address_to_str (dst_address), dst_port, data); conv = g_malloc (sizeof (conversation_t)); g_assert(conv); address_copy(&conv->src_address, src_address); address_copy(&conv->dst_address, dst_address); conv->src_port = src_port; conv->dst_port = dst_port; conv->data = g_strdup (data); conversations = g_list_prepend (conversations, conv); n_conversations++; } /* add_conversation */
} static void ansi_tcap_init_protocol(void) { ansi_tcap_init_transaction_table(); } /* Store Invoke information needed for the corresponding reply */ static void save_invoke_data(packet_info *pinfo, proto_tree *tree _U_, tvbuff_t *tvb _U_){ struct ansi_tcap_invokedata_t *ansi_tcap_saved_invokedata; gchar *src, *dst; char *buf; src = address_to_str(wmem_packet_scope(), &(pinfo->src)); dst = address_to_str(wmem_packet_scope(), &(pinfo->dst)); if ((!pinfo->fd->flags.visited)&&(ansi_tcap_private.TransactionID_str)){ /* Only do this once XXX I hope its the right thing to do */ /* The hash string needs to contain src and dest to distiguish differnt flows */ switch(ansi_tcap_response_matching_type){ case 0: buf = wmem_strdup(wmem_packet_scope(), ansi_tcap_private.TransactionID_str); break; case 1: buf = wmem_strdup_printf(wmem_packet_scope(), "%s%s",ansi_tcap_private.TransactionID_str,src); break; default: buf = wmem_strdup_printf(wmem_packet_scope(), "%s%s%s",ansi_tcap_private.TransactionID_str,src,dst);
char *get_conversation_filter(conv_item_t *conv_item, conv_direction_e direction) { char *sport, *dport, *src_addr, *dst_addr; char *str; sport = ct_port_to_str(conv_item->ptype, conv_item->src_port); dport = ct_port_to_str(conv_item->ptype, conv_item->dst_port); src_addr = address_to_str(NULL, &conv_item->src_address); dst_addr = address_to_str(NULL, &conv_item->dst_address); if (conv_item->src_address.type == AT_STRINGZ || conv_item->src_address.type == AT_USB) { char *new_addr; new_addr = wmem_strdup_printf(NULL, "\"%s\"", src_addr); wmem_free(NULL, src_addr); src_addr = new_addr; } if (conv_item->dst_address.type == AT_STRINGZ || conv_item->dst_address.type == AT_USB) { char *new_addr; new_addr = wmem_strdup_printf(NULL, "\"%s\"", dst_addr); wmem_free(NULL, dst_addr); dst_addr = new_addr; } switch(direction){ case CONV_DIR_A_TO_FROM_B: /* A <-> B */ str = wmem_strdup_printf(NULL, "%s==%s%s%s%s%s && %s==%s%s%s%s%s", conversation_get_filter_name(conv_item, CONV_FT_ANY_ADDRESS), src_addr, sport?" && ":"", sport?conversation_get_filter_name(conv_item, CONV_FT_ANY_PORT):"", sport?"==":"", sport?sport:"", conversation_get_filter_name(conv_item, CONV_FT_ANY_ADDRESS), dst_addr, dport?" && ":"", dport?conversation_get_filter_name(conv_item, CONV_FT_ANY_PORT):"", dport?"==":"", dport?dport:"" ); break; case CONV_DIR_A_TO_B: /* A --> B */ str = wmem_strdup_printf(NULL, "%s==%s%s%s%s%s && %s==%s%s%s%s%s", conversation_get_filter_name(conv_item, CONV_FT_SRC_ADDRESS), src_addr, sport?" && ":"", sport?conversation_get_filter_name(conv_item, CONV_FT_SRC_PORT):"", sport?"==":"", sport?sport:"", conversation_get_filter_name(conv_item, CONV_FT_DST_ADDRESS), dst_addr, dport?" && ":"", dport?conversation_get_filter_name(conv_item, CONV_FT_DST_PORT):"", dport?"==":"", dport?dport:"" ); break; case CONV_DIR_A_FROM_B: /* A <-- B */ str = wmem_strdup_printf(NULL, "%s==%s%s%s%s%s && %s==%s%s%s%s%s", conversation_get_filter_name(conv_item, CONV_FT_DST_ADDRESS), src_addr, sport?" && ":"", sport?conversation_get_filter_name(conv_item, CONV_FT_DST_PORT):"", sport?"==":"", sport?sport:"", conversation_get_filter_name(conv_item, CONV_FT_SRC_ADDRESS), dst_addr, dport?" && ":"", dport?conversation_get_filter_name(conv_item, CONV_FT_SRC_PORT):"", dport?"==":"", dport?dport:"" ); break; case CONV_DIR_A_TO_FROM_ANY: /* A <-> ANY */ str = wmem_strdup_printf(NULL, "%s==%s%s%s%s%s", conversation_get_filter_name(conv_item, CONV_FT_ANY_ADDRESS), src_addr, sport?" && ":"", sport?conversation_get_filter_name(conv_item, CONV_FT_ANY_PORT):"", sport?"==":"", sport?sport:"" ); break; case CONV_DIR_A_TO_ANY: /* A --> ANY */ str = wmem_strdup_printf(NULL, "%s==%s%s%s%s%s", conversation_get_filter_name(conv_item, CONV_FT_SRC_ADDRESS), src_addr, sport?" && ":"", sport?conversation_get_filter_name(conv_item, CONV_FT_SRC_PORT):"", sport?"==":"", sport?sport:"" ); break; case CONV_DIR_A_FROM_ANY: /* A <-- ANY */ str = wmem_strdup_printf(NULL, "%s==%s%s%s%s%s", conversation_get_filter_name(conv_item, CONV_FT_DST_ADDRESS), src_addr, sport?" && ":"", sport?conversation_get_filter_name(conv_item, CONV_FT_DST_PORT):"", sport?"==":"", sport?sport:"" ); break; case CONV_DIR_ANY_TO_FROM_B: /* ANY <-> B */ str = wmem_strdup_printf(NULL, "%s==%s%s%s%s%s", conversation_get_filter_name(conv_item, CONV_FT_ANY_ADDRESS), dst_addr, dport?" && ":"", dport?conversation_get_filter_name(conv_item, CONV_FT_ANY_PORT):"", dport?"==":"", dport?dport:"" ); break; case CONV_DIR_ANY_FROM_B: /* ANY <-- B */ str = wmem_strdup_printf(NULL, "%s==%s%s%s%s%s", conversation_get_filter_name(conv_item, CONV_FT_SRC_ADDRESS), dst_addr, dport?" && ":"", dport?conversation_get_filter_name(conv_item, CONV_FT_SRC_PORT):"", dport?"==":"", dport?dport:"" ); break; case CONV_DIR_ANY_TO_B: /* ANY --> B */ str = wmem_strdup_printf(NULL, "%s==%s%s%s%s%s", conversation_get_filter_name(conv_item, CONV_FT_DST_ADDRESS), dst_addr, dport?" && ":"", dport?conversation_get_filter_name(conv_item, CONV_FT_DST_PORT):"", dport?"==":"", dport?dport:"" ); break; default: str = wmem_strdup(NULL, "INVALID"); break; } g_free(sport); g_free(dport); wmem_free(NULL, src_addr); wmem_free(NULL, dst_addr); return str; }
copy_address_shallow(&pinfo->dst, &pinfo->dl_dst); dst_ssid = tvb_get_guint8(tvb, offset+6); /* step over dst addr point at src addr */ offset += AX25_ADDR_LEN; proto_tree_add_item( ax25_tree, hf_ax25_src, tvb, offset, AX25_ADDR_LEN, ENC_NA); set_address_tvb(&pinfo->dl_src, AT_AX25, AX25_ADDR_LEN, tvb, offset); copy_address_shallow(&pinfo->src, &pinfo->dl_src); src_ssid = tvb_get_guint8(tvb, offset+6); /* step over src addr point at either 1st via addr or control byte */ offset += AX25_ADDR_LEN; proto_item_append_text( ti, ", Src: %s, Dst: %s", address_to_str(wmem_packet_scope(), &pinfo->src), address_to_str(wmem_packet_scope(), &pinfo->dst)); /* decode the cmd/resp field */ /* v2cmdresp = '.'; */ switch ( ( (dst_ssid >> 6) & 0x02) | ( (src_ssid >> 7) & 0x01 ) ) { case 1 : /* V2.0 Response */ ax25_version = "V2.0+"; /* v2cmdresp = 'R'; */ is_response = TRUE; break; case 2 : /* V2.0 Command */ ax25_version = "V2.0+"; /* v2cmdresp = 'C'; */ is_response = FALSE;
gcp_msg_t* gcp_msg(packet_info* pinfo, int o, gboolean keep_persistent_data) { gcp_msg_t* m; guint32 framenum = (guint32)pinfo->num; guint32 offset = (guint32)o; address* src = &(pinfo->src); address* dst = &(pinfo->dst); address* lo_addr; address* hi_addr; if (keep_persistent_data) { wmem_tree_key_t key[3]; key[0].length = 1; key[0].key = &(framenum); key[1].length = 1; key[1].key = &offset; key[2].length = 0; key[2].key =NULL; if (( m = (gcp_msg_t *)wmem_tree_lookup32_array(msgs,key) )) { m->committed = TRUE; return m; } else { m = wmem_new(wmem_file_scope(), gcp_msg_t); m->framenum = framenum; m->time = pinfo->abs_ts; m->trxs = NULL; m->committed = FALSE; wmem_tree_insert32_array(msgs,key,m); } } else { m = wmem_new0(wmem_packet_scope(), gcp_msg_t); m->framenum = framenum; m->trxs = NULL; m->committed = FALSE; } if (cmp_address(src, dst) < 0) { lo_addr = src; hi_addr = dst; } else { lo_addr = dst; hi_addr = src; } switch(lo_addr->type) { case AT_NONE: m->lo_addr = 0; m->hi_addr = 0; break; case AT_IPv4: memcpy((guint8*)&(m->hi_addr),hi_addr->data,4); memcpy((guint8*)&(m->lo_addr),lo_addr->data,4); break; case AT_SS7PC: m->hi_addr = mtp3_pc_hash((const mtp3_addr_pc_t *)hi_addr->data); m->lo_addr = mtp3_pc_hash((const mtp3_addr_pc_t *)lo_addr->data); break; default: /* XXX: heuristic and error prone */ m->hi_addr = g_str_hash(address_to_str(wmem_packet_scope(), hi_addr)); m->lo_addr = g_str_hash(address_to_str(wmem_packet_scope(), lo_addr)); break; } return m; }
static int ip_hosts_stats_tree_packet(stats_tree *st, packet_info *pinfo, int st_node, const gchar *st_str) { tick_stat_node(st, st_str, 0, FALSE); tick_stat_node(st, address_to_str(pinfo->pool, &pinfo->net_src), st_node, FALSE); tick_stat_node(st, address_to_str(pinfo->pool, &pinfo->net_dst), st_node, FALSE); return 1; }
static void dissect_vektor_igrp (tvbuff_t *tvb, proto_tree *igrp_vektor_tree, guint8 network) { union { guint8 addr_bytes[4]; guint32 addr_word; } addr; address ip_addr; if (network != 0) { /* * Interior route; network is the high-order byte, and the three * bytes in the vector are the lower 3 bytes. */ addr.addr_bytes[0]=network; addr.addr_bytes[1]=tvb_get_guint8(tvb,0); addr.addr_bytes[2]=tvb_get_guint8(tvb,1); addr.addr_bytes[3]=tvb_get_guint8(tvb,2); } else { /* * System or exterior route; the three bytes in the vector are * the three high-order bytes, and the low-order byte is 0. */ addr.addr_bytes[0]=tvb_get_guint8(tvb,0); addr.addr_bytes[1]=tvb_get_guint8(tvb,1); addr.addr_bytes[2]=tvb_get_guint8(tvb,2); addr.addr_bytes[3]=0; } set_address(&ip_addr, AT_IPv4, 4, &addr); igrp_vektor_tree = proto_tree_add_subtree_format(igrp_vektor_tree, tvb, 0 ,14, ett_igrp_net, NULL, "Entry for network %s", address_to_str(wmem_packet_scope(), &ip_addr)); proto_tree_add_ipv4(igrp_vektor_tree, hf_igrp_network, tvb, 0, 3, addr.addr_word); proto_tree_add_item(igrp_vektor_tree, hf_igrp_delay, tvb, 3, 3, ENC_BIG_ENDIAN); proto_tree_add_item(igrp_vektor_tree, hf_igrp_bandwidth, tvb, 6, 3, ENC_BIG_ENDIAN); proto_tree_add_uint_format_value(igrp_vektor_tree, hf_igrp_mtu, tvb, 9, 2, tvb_get_ntohs(tvb,9), "%d bytes", tvb_get_ntohs(tvb,9)); proto_tree_add_item(igrp_vektor_tree, hf_igrp_reliability, tvb, 11, 1, ENC_BIG_ENDIAN); proto_tree_add_item(igrp_vektor_tree, hf_igrp_load, tvb, 12, 1, ENC_BIG_ENDIAN); proto_tree_add_item(igrp_vektor_tree, hf_igrp_hop_count, tvb, 13, 1, ENC_BIG_ENDIAN); }
/* * Fetch the list of local interfaces with capture_interface_list() * and set the list of "all interfaces" in *capture_opts to include * those interfaces. */ void scan_local_interfaces(void (*update_cb)(void)) { GList *if_entry, *lt_entry, *if_list; if_info_t *if_info, temp; gchar *descr; if_capabilities_t *caps=NULL; gint linktype_count; gboolean monitor_mode; GSList *curr_addr; int ips = 0, i; guint count = 0, j; if_addr_t *addr, *temp_addr; link_row *link = NULL; data_link_info_t *data_link_info; interface_t device; GString *ip_str; interface_options interface_opts; gboolean found = FALSE; if (global_capture_opts.all_ifaces->len > 0) { for (i = (int)global_capture_opts.all_ifaces->len-1; i >= 0; i--) { device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); if (device.local && device.type != IF_PIPE && device.type != IF_STDIN) { global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i); if (device.selected) { global_capture_opts.num_selected--; /* if device was to be used after this statement, we should set device.selected=FALSE here */ } /* if we remove an interface from all_interfaces, it must also be removed from ifaces if it is present there otherwise, it would be re-added to all_interfaces below (interfaces set with -i on the command line are initially present in ifaces but not in all_interfaces, but these interfaces are not removed here) */ for (j = 0; j < global_capture_opts.ifaces->len; j++) { interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, j); if (strcmp(device.name, interface_opts.name) == 0) { /* 2nd param must be the index of ifaces (not all_ifaces) */ capture_opts_del_iface(&global_capture_opts, j); } } capture_opts_free_interface_t(&device); } } } /* Scan through the list and build a list of strings to display. */ g_free(global_capture_opts.ifaces_err_info); if_list = capture_interface_list(&global_capture_opts.ifaces_err, &global_capture_opts.ifaces_err_info, update_cb); count = 0; for (if_entry = if_list; if_entry != NULL; if_entry = g_list_next(if_entry)) { memset(&device, 0, sizeof(device)); if_info = (if_info_t *)if_entry->data; ip_str = g_string_new(""); ips = 0; if (strstr(if_info->name, "rpcap:")) { continue; } device.name = g_strdup(if_info->name); if (if_info->friendly_name != NULL) { device.friendly_name = g_strdup(if_info->friendly_name); } else { device.friendly_name = NULL; } device.hidden = FALSE; device.locked = FALSE; memset(&temp, 0, sizeof(temp)); temp.name = g_strdup(if_info->name); temp.friendly_name = g_strdup(if_info->friendly_name); temp.vendor_description = g_strdup(if_info->vendor_description); temp.loopback = if_info->loopback; temp.type = if_info->type; #ifdef HAVE_EXTCAP temp.extcap = g_strdup(if_info->extcap); #endif /* Is this interface hidden and, if so, should we include it anyway? */ descr = capture_dev_user_descr_find(if_info->name); device.display_name = get_iface_display_name(descr, if_info); g_free(descr); device.selected = FALSE; if (prefs_is_capture_device_hidden(if_info->name)) { device.hidden = TRUE; } device.type = if_info->type; monitor_mode = prefs_capture_device_monitor_mode(if_info->name); caps = capture_get_if_capabilities(if_info->name, monitor_mode, NULL, NULL, update_cb); for (; (curr_addr = g_slist_nth(if_info->addrs, ips)) != NULL; ips++) { temp_addr = (if_addr_t *)g_malloc0(sizeof(if_addr_t)); if (ips != 0) { g_string_append(ip_str, "\n"); } addr = (if_addr_t *)curr_addr->data; if (addr) { address addr_str; char* temp_addr_str = NULL; temp_addr->ifat_type = addr->ifat_type; switch (addr->ifat_type) { case IF_AT_IPv4: temp_addr->addr.ip4_addr = addr->addr.ip4_addr; set_address(&addr_str, AT_IPv4, 4, &addr->addr.ip4_addr); temp_addr_str = address_to_str(NULL, &addr_str); g_string_append(ip_str, temp_addr_str); break; case IF_AT_IPv6: memcpy(temp_addr->addr.ip6_addr, addr->addr.ip6_addr, sizeof(addr->addr)); set_address(&addr_str, AT_IPv6, 16, addr->addr.ip6_addr); temp_addr_str = address_to_str(NULL, &addr_str); g_string_append(ip_str, temp_addr_str); break; default: /* In case we add non-IP addresses */ break; } wmem_free(NULL, temp_addr_str); } else { g_free(temp_addr); temp_addr = NULL; } if (temp_addr) { temp.addrs = g_slist_append(temp.addrs, temp_addr); } } #ifdef HAVE_PCAP_REMOTE device.local = TRUE; device.remote_opts.src_type = CAPTURE_IFLOCAL; device.remote_opts.remote_host_opts.remote_host = g_strdup(global_capture_opts.default_options.remote_host); device.remote_opts.remote_host_opts.remote_port = g_strdup(global_capture_opts.default_options.remote_port); device.remote_opts.remote_host_opts.auth_type = global_capture_opts.default_options.auth_type; device.remote_opts.remote_host_opts.auth_username = g_strdup(global_capture_opts.default_options.auth_username); device.remote_opts.remote_host_opts.auth_password = g_strdup(global_capture_opts.default_options.auth_password); device.remote_opts.remote_host_opts.datatx_udp = global_capture_opts.default_options.datatx_udp; device.remote_opts.remote_host_opts.nocap_rpcap = global_capture_opts.default_options.nocap_rpcap; device.remote_opts.remote_host_opts.nocap_local = global_capture_opts.default_options.nocap_local; #endif #ifdef HAVE_PCAP_SETSAMPLING device.remote_opts.sampling_method = global_capture_opts.default_options.sampling_method; device.remote_opts.sampling_param = global_capture_opts.default_options.sampling_param; #endif linktype_count = 0; device.links = NULL; if (caps != NULL) { #if defined(HAVE_PCAP_CREATE) device.monitor_mode_enabled = monitor_mode; device.monitor_mode_supported = caps->can_set_rfmon; #endif /* * Process the list of link-layer header types. */ for (lt_entry = caps->data_link_types; lt_entry != NULL; lt_entry = g_list_next(lt_entry)) { data_link_info = (data_link_info_t *)lt_entry->data; link = (link_row *)g_malloc(sizeof(link_row)); if (data_link_info->description != NULL) { link->dlt = data_link_info->dlt; link->name = g_strdup_printf("%s", data_link_info->description); } else { link->dlt = -1; link->name = g_strdup_printf("%s (not supported)", data_link_info->name); } device.links = g_list_append(device.links, link); linktype_count++; } /* * Set the active DLT for the device appropriately. */ set_active_dlt(&device, global_capture_opts.default_options.linktype); } else { #if defined(HAVE_PCAP_CREATE) device.monitor_mode_enabled = FALSE; device.monitor_mode_supported = FALSE; #endif device.active_dlt = -1; } device.addresses = g_strdup(ip_str->str); device.no_addresses = ips; device.local = TRUE; device.if_info = temp; device.last_packets = 0; if (!capture_dev_user_pmode_find(if_info->name, &device.pmode)) { device.pmode = global_capture_opts.default_options.promisc_mode; } if (!capture_dev_user_snaplen_find(if_info->name, &device.has_snaplen, &device.snaplen)) { device.has_snaplen = global_capture_opts.default_options.has_snaplen; device.snaplen = global_capture_opts.default_options.snaplen; } device.cfilter = g_strdup(global_capture_opts.default_options.cfilter); #ifdef CAN_SET_CAPTURE_BUFFER_SIZE if ((device.buffer = capture_dev_user_buffersize_find(if_info->name)) == -1) { device.buffer = global_capture_opts.default_options.buffer_size; } #endif fill_from_ifaces(&device); #ifdef HAVE_EXTCAP /* Extcap devices start with no cached args */ device.external_cap_args_settings = NULL; #endif if (global_capture_opts.all_ifaces->len <= count) { g_array_append_val(global_capture_opts.all_ifaces, device); count = global_capture_opts.all_ifaces->len; } else { g_array_insert_val(global_capture_opts.all_ifaces, count, device); } if (caps != NULL) { free_if_capabilities(caps); } g_string_free(ip_str, TRUE); count++; } free_interface_list(if_list); /* see whether there are additional interfaces in ifaces */ for (j = 0; j < global_capture_opts.ifaces->len; j++) { interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, j); found = FALSE; for (i = 0; i < (int)global_capture_opts.all_ifaces->len; i++) { device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); if (strcmp(device.name, interface_opts.name) == 0) { found = TRUE; break; } } if (!found) { /* new interface, maybe a pipe */ memset(&device, 0, sizeof(device)); device.name = g_strdup(interface_opts.name); device.display_name = interface_opts.descr ? g_strdup_printf("%s: %s", device.name, interface_opts.descr) : g_strdup_printf("%s", device.name); device.hidden = FALSE; device.selected = TRUE; device.type = IF_PIPE; #ifdef CAN_SET_CAPTURE_BUFFER_SIZE device.buffer = interface_opts.buffer_size; #endif #if defined(HAVE_PCAP_CREATE) device.monitor_mode_enabled = interface_opts.monitor_mode; device.monitor_mode_supported = FALSE; #endif device.pmode = interface_opts.promisc_mode; device.has_snaplen = interface_opts.has_snaplen; device.snaplen = interface_opts.snaplen; device.cfilter = g_strdup(interface_opts.cfilter); device.active_dlt = interface_opts.linktype; device.addresses = NULL; device.no_addresses = 0; device.last_packets = 0; device.links = NULL; device.local = TRUE; device.locked = FALSE; device.if_info.name = g_strdup(interface_opts.name); device.if_info.friendly_name = NULL; device.if_info.vendor_description = g_strdup(interface_opts.descr); device.if_info.addrs = NULL; device.if_info.loopback = FALSE; #ifdef HAVE_EXTCAP device.if_info.extcap = g_strdup(interface_opts.extcap); #endif g_array_append_val(global_capture_opts.all_ifaces, device); global_capture_opts.num_selected++; } } }
static void dissect_netrom_proto(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { proto_item *ti; proto_tree *netrom_tree; int offset; #if 0 guint8 src_ssid; guint8 dst_ssid; #endif guint8 op_code; guint8 cct_index; guint8 cct_id; tvbuff_t *next_tvb; col_set_str( pinfo->cinfo, COL_PROTOCOL, "NET/ROM" ); col_clear( pinfo->cinfo, COL_INFO ); offset = 0; /* source */ TVB_SET_ADDRESS(&pinfo->dl_src, AT_AX25, tvb, offset, AX25_ADDR_LEN); TVB_SET_ADDRESS(&pinfo->src, AT_AX25, tvb, offset, AX25_ADDR_LEN); /* src_ssid = tvb_get_guint8(tvb, offset+6); */ offset += AX25_ADDR_LEN; /* step over src addr */ /* destination */ TVB_SET_ADDRESS(&pinfo->dl_dst, AT_AX25, tvb, offset, AX25_ADDR_LEN); TVB_SET_ADDRESS(&pinfo->dst, AT_AX25, tvb, offset, AX25_ADDR_LEN); /* dst_ssid = tvb_get_guint8(tvb, offset+6); */ offset += AX25_ADDR_LEN; /* step over dst addr */ offset += 1; /* step over ttl */ cct_index = tvb_get_guint8( tvb, offset ); offset += 1; /* step over cct index*/ cct_id = tvb_get_guint8( tvb, offset ); offset += 1; /* step over cct id */ offset += 1; /* step over n_s */ offset += 1; /* step over n_r */ /* frame type */ op_code = tvb_get_guint8( tvb, offset ) & 0x0f; /*offset += 1;*/ /* step over op_code */ col_add_fstr( pinfo->cinfo, COL_INFO, "%s", val_to_str_const( op_code, op_code_vals_text, "Unknown" )); /* if ( tree ) */ { /* create display subtree for the protocol */ ti = proto_tree_add_protocol_format( tree, proto_netrom, tvb, 0, NETROM_HEADER_SIZE, "NET/ROM, Src: %s, Dst: %s", address_to_str(wmem_packet_scope(), &pinfo->src), address_to_str(wmem_packet_scope(), &pinfo->dst)); netrom_tree = proto_item_add_subtree( ti, ett_netrom ); offset = 0; /* source */ proto_tree_add_item( netrom_tree, hf_netrom_src, tvb, offset, AX25_ADDR_LEN, ENC_NA ); offset += AX25_ADDR_LEN; /* destination */ proto_tree_add_item( netrom_tree, hf_netrom_dst, tvb, offset, AX25_ADDR_LEN, ENC_NA ); offset += AX25_ADDR_LEN; /* ttl */ proto_tree_add_item( netrom_tree, hf_netrom_ttl, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; switch ( op_code ) { case NETROM_PROTOEXT : /* cct index */ proto_tree_add_item( netrom_tree, hf_netrom_my_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; /* cct id */ proto_tree_add_item( netrom_tree, hf_netrom_my_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; /* unused */ offset += 1; /* unused */ offset += 1; break; case NETROM_CONNREQ : /* cct index */ proto_tree_add_item( netrom_tree, hf_netrom_my_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; /* cct id */ proto_tree_add_item( netrom_tree, hf_netrom_my_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; /* unused */ offset += 1; /* unused */ offset += 1; break; case NETROM_CONNACK : /* your cct index */ proto_tree_add_item( netrom_tree, hf_netrom_your_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; /* your cct id */ proto_tree_add_item( netrom_tree, hf_netrom_your_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; /* my cct index */ proto_tree_add_item( netrom_tree, hf_netrom_my_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; /* my cct id */ proto_tree_add_item( netrom_tree, hf_netrom_my_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; break; case NETROM_DISCREQ : /* your cct index */ proto_tree_add_item( netrom_tree, hf_netrom_your_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; /* your cct id */ proto_tree_add_item( netrom_tree, hf_netrom_your_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; /* unused */ offset += 1; /* unused */ offset += 1; break; case NETROM_DISCACK : /* your cct index */ proto_tree_add_item( netrom_tree, hf_netrom_your_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; /* your cct id */ proto_tree_add_item( netrom_tree, hf_netrom_your_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; /* unused */ offset += 1; /* unused */ offset += 1; break; case NETROM_INFO : /* your cct index */ proto_tree_add_item( netrom_tree, hf_netrom_your_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; /* your cct id */ proto_tree_add_item( netrom_tree, hf_netrom_your_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; /* n_s */ proto_tree_add_item( netrom_tree, hf_netrom_n_s, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; /* n_r */ proto_tree_add_item( netrom_tree, hf_netrom_n_r, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; break; case NETROM_INFOACK : /* your cct index */ proto_tree_add_item( netrom_tree, hf_netrom_your_cct_index, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; /* your cct id */ proto_tree_add_item( netrom_tree, hf_netrom_your_cct_id, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; /* unused */ offset += 1; /* n_r */ proto_tree_add_item( netrom_tree, hf_netrom_n_r, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; break; default : offset += 1; offset += 1; offset += 1; offset += 1; break; } /* type */ dissect_netrom_type( tvb, offset, pinfo, netrom_tree, hf_netrom_type, ett_netrom_type, &netrom_type_items ); offset += 1; switch ( op_code ) { case NETROM_PROTOEXT : break; case NETROM_CONNREQ : /* proposed window size */ proto_tree_add_item( netrom_tree, hf_netrom_pwindow, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; proto_tree_add_item( netrom_tree, hf_netrom_user, tvb, offset, AX25_ADDR_LEN, ENC_NA ); offset += AX25_ADDR_LEN; proto_tree_add_item( netrom_tree, hf_netrom_node, tvb, offset, AX25_ADDR_LEN, ENC_NA ); offset += AX25_ADDR_LEN; break; case NETROM_CONNACK : /* accepted window size */ proto_tree_add_item( netrom_tree, hf_netrom_awindow, tvb, offset, 1, ENC_BIG_ENDIAN ); offset += 1; break; case NETROM_DISCREQ : break; case NETROM_DISCACK : break; case NETROM_INFO : break; case NETROM_INFOACK : break; default : break; } } /* Call sub-dissectors here */ next_tvb = tvb_new_subset_remaining(tvb, offset); switch ( op_code ) { case NETROM_PROTOEXT : if ( cct_index == NETROM_PROTO_IP && cct_id == NETROM_PROTO_IP ) call_dissector( ip_handle , next_tvb, pinfo, tree ); else call_dissector( data_handle , next_tvb, pinfo, tree ); break; case NETROM_INFO : default : call_dissector( data_handle , next_tvb, pinfo, tree ); break; } }
void ManageInterfacesDialog::addRemoteInterfaces(GList* rlist, remote_options *roptions) { GList *if_entry, *lt_entry; if_info_t *if_info; char *if_string = NULL; gchar *descr, *str = NULL, *link_type_name = NULL, *auth_str; if_capabilities_t *caps; gint linktype_count; bool monitor_mode, found = false; GSList *curr_addr; int ips = 0; guint i; if_addr_t *addr; data_link_info_t *data_link_info; GString *ip_str; link_row *linkr = NULL; interface_t device; guint num_interfaces = global_capture_opts.all_ifaces->len; for (if_entry = g_list_first(rlist); if_entry != NULL; if_entry = g_list_next(if_entry)) { auth_str = NULL; if_info = (if_info_t *)if_entry->data; for (i = 0; i < num_interfaces; i++) { device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); if (device.hidden) continue; if (strcmp(device.name, if_info->name) == 0) { found = TRUE; break; } } if (found) { found = FALSE; continue; } ip_str = g_string_new(""); str = ""; ips = 0; device.name = g_strdup(if_info->name); /* Is this interface hidden and, if so, should we include it anyway? */ descr = capture_dev_user_descr_find(if_info->name); if (descr != NULL) { /* Yes, we have a user-supplied description; use it. */ if_string = g_strdup_printf("%s: %s", descr, if_info->name); g_free(descr); } else { /* No, we don't have a user-supplied description; did we get one from the OS or libpcap? */ if (if_info->vendor_description != NULL) { /* Yes - use it. */ if_string = g_strdup_printf("%s: %s", if_info->vendor_description, if_info->name); } else { /* No. */ if_string = g_strdup(if_info->name); } } /* else descr != NULL */ if (if_info->loopback) { device.display_name = g_strdup_printf("%s (loopback)", if_string); } else { device.display_name = g_strdup(if_string); } #ifdef CAN_SET_CAPTURE_BUFFER_SIZE if ((device.buffer = capture_dev_user_buffersize_find(if_string)) == -1) { device.buffer = global_capture_opts.default_options.buffer_size; } #endif if (!capture_dev_user_pmode_find(if_string, &device.pmode)) { device.pmode = global_capture_opts.default_options.promisc_mode; } if (!capture_dev_user_snaplen_find(if_string, &device.has_snaplen, &device.snaplen)) { device.has_snaplen = global_capture_opts.default_options.has_snaplen; device.snaplen = global_capture_opts.default_options.snaplen; } device.cfilter = g_strdup(global_capture_opts.default_options.cfilter); monitor_mode = prefs_capture_device_monitor_mode(if_string); #ifdef HAVE_PCAP_REMOTE if (roptions->remote_host_opts.auth_type == CAPTURE_AUTH_PWD) { auth_str = g_strdup_printf("%s:%s", roptions->remote_host_opts.auth_username, roptions->remote_host_opts.auth_password); } #endif caps = capture_get_if_capabilities(if_string, monitor_mode, auth_str, NULL, main_window_update); g_free(auth_str); for (; (curr_addr = g_slist_nth(if_info->addrs, ips)) != NULL; ips++) { address addr_str; char* temp_addr_str = NULL; if (ips != 0) { g_string_append(ip_str, "\n"); } addr = (if_addr_t *)curr_addr->data; switch (addr->ifat_type) { case IF_AT_IPv4: SET_ADDRESS(&addr_str, AT_IPv4, 4, &addr->addr.ip4_addr); temp_addr_str = (char*)address_to_str(NULL, &addr_str); g_string_append(ip_str, temp_addr_str); break; case IF_AT_IPv6: SET_ADDRESS(&addr_str, AT_IPv6, 16, addr->addr.ip6_addr); temp_addr_str = (char*)address_to_str(NULL, &addr_str); g_string_append(ip_str, temp_addr_str); break; default: /* In case we add non-IP addresses */ break; } wmem_free(NULL, temp_addr_str); } /* for curr_addr */ linktype_count = 0; device.links = NULL; if (caps != NULL) { #ifdef HAVE_PCAP_CREATE device.monitor_mode_enabled = monitor_mode; device.monitor_mode_supported = caps->can_set_rfmon; #endif for (lt_entry = caps->data_link_types; lt_entry != NULL; lt_entry = g_list_next(lt_entry)) { data_link_info = (data_link_info_t *)lt_entry->data; linkr = (link_row *)g_malloc(sizeof(link_row)); /* * For link-layer types libpcap/WinPcap doesn't know about, the * name will be "DLT n", and the description will be null. * We mark those as unsupported, and don't allow them to be * used. */ if (data_link_info->description != NULL) { str = g_strdup_printf("%s", data_link_info->description); linkr->dlt = data_link_info->dlt; } else { str = g_strdup_printf("%s (not supported)", data_link_info->name); linkr->dlt = -1; } if (linktype_count == 0) { link_type_name = g_strdup(str); device.active_dlt = data_link_info->dlt; } linkr->name = g_strdup(str); g_free(str); device.links = g_list_append(device.links, linkr); linktype_count++; } /* for link_types */ } else { #if defined(HAVE_PCAP_CREATE) device.monitor_mode_enabled = FALSE; device.monitor_mode_supported = FALSE; #endif device.active_dlt = -1; link_type_name = g_strdup("default"); } device.addresses = g_strdup(ip_str->str); device.no_addresses = ips; device.remote_opts.src_type= roptions->src_type; if (device.remote_opts.src_type == CAPTURE_IFREMOTE) { device.local = FALSE; } device.remote_opts.remote_host_opts.remote_host = g_strdup(roptions->remote_host_opts.remote_host); device.remote_opts.remote_host_opts.remote_port = g_strdup(roptions->remote_host_opts.remote_port); device.remote_opts.remote_host_opts.auth_type = roptions->remote_host_opts.auth_type; device.remote_opts.remote_host_opts.auth_username = g_strdup(roptions->remote_host_opts.auth_username); device.remote_opts.remote_host_opts.auth_password = g_strdup(roptions->remote_host_opts.auth_password); device.remote_opts.remote_host_opts.datatx_udp = roptions->remote_host_opts.datatx_udp; device.remote_opts.remote_host_opts.nocap_rpcap = roptions->remote_host_opts.nocap_rpcap; device.remote_opts.remote_host_opts.nocap_local = roptions->remote_host_opts.nocap_local; #ifdef HAVE_PCAP_SETSAMPLING device.remote_opts.sampling_method = roptions->sampling_method; device.remote_opts.sampling_param = roptions->sampling_param; #endif device.selected = TRUE; global_capture_opts.num_selected++; g_array_append_val(global_capture_opts.all_ifaces, device); g_string_free(ip_str, TRUE); } /*for*/ showRemoteInterfaces(); }
static gboolean lbm_uimflow_add_to_graph(seq_analysis_info_t * seq_info, packet_info * pinfo, const lbm_uim_stream_info_t * stream_info) { lbm_uim_stream_endpoint_t epa; lbm_uim_stream_endpoint_t epb; seq_analysis_item_t * item; gchar * ctxinst1 = NULL; gchar * ctxinst2 = NULL; gboolean swap_endpoints = FALSE; int rc; if (stream_info->endpoint_a.type != stream_info->endpoint_b.type) { return (FALSE); } if (stream_info->endpoint_a.type == lbm_uim_instance_stream) { rc = memcmp((void *)stream_info->endpoint_a.stream_info.ctxinst.ctxinst, (void *)stream_info->endpoint_b.stream_info.ctxinst.ctxinst, LBM_CONTEXT_INSTANCE_BLOCK_SZ); if (rc <= 0) { swap_endpoints = FALSE; } else { swap_endpoints = TRUE; } } else { if (stream_info->endpoint_a.stream_info.dest.domain < stream_info->endpoint_b.stream_info.dest.domain) { swap_endpoints = FALSE; } else if (stream_info->endpoint_a.stream_info.dest.domain > stream_info->endpoint_b.stream_info.dest.domain) { swap_endpoints = TRUE; } else { int compare; compare = CMP_ADDRESS(&(stream_info->endpoint_a.stream_info.dest.addr), &(stream_info->endpoint_b.stream_info.dest.addr)); if (compare < 0) { swap_endpoints = FALSE; } else if (compare > 0) { swap_endpoints = TRUE; } else { if (stream_info->endpoint_a.stream_info.dest.port <= stream_info->endpoint_b.stream_info.dest.port) { swap_endpoints = FALSE; } else { swap_endpoints = TRUE; } } } } if (swap_endpoints == FALSE) { epa = stream_info->endpoint_a; epb = stream_info->endpoint_b; } else { epb = stream_info->endpoint_a; epa = stream_info->endpoint_b; } item = (seq_analysis_item_t *)g_malloc(sizeof(seq_analysis_item_t)); COPY_ADDRESS(&(item->src_addr), &(pinfo->src)); COPY_ADDRESS(&(item->dst_addr), &(pinfo->dst)); item->fd = pinfo->fd; item->port_src = pinfo->srcport; item->port_dst = pinfo->destport; if (stream_info->description == NULL) { item->frame_label = g_strdup_printf("(%" G_GUINT32_FORMAT ")", stream_info->sqn); } else { item->frame_label = g_strdup_printf("%s (%" G_GUINT32_FORMAT ")", stream_info->description, stream_info->sqn); } if (epa.type == lbm_uim_instance_stream) { ctxinst1 = bytes_to_str(pinfo->pool, epa.stream_info.ctxinst.ctxinst, sizeof(epa.stream_info.ctxinst.ctxinst)); ctxinst2 = bytes_to_str(pinfo->pool, epb.stream_info.ctxinst.ctxinst, sizeof(epb.stream_info.ctxinst.ctxinst)); item->comment = g_strdup_printf("%s <-> %s [%" G_GUINT64_FORMAT "]", ctxinst1, ctxinst2, stream_info->channel); } else { item->comment = g_strdup_printf("%" G_GUINT32_FORMAT ":%s:%" G_GUINT16_FORMAT " <-> %" G_GUINT32_FORMAT ":%s:%" G_GUINT16_FORMAT " [%" G_GUINT64_FORMAT "]", epa.stream_info.dest.domain, address_to_str(pinfo->pool, &(epa.stream_info.dest.addr)), epa.stream_info.dest.port, epb.stream_info.dest.domain, address_to_str(pinfo->pool, &(epb.stream_info.dest.addr)), epb.stream_info.dest.port, stream_info->channel); } item->conv_num = (guint16)LBM_CHANNEL_ID(stream_info->channel); item->display = TRUE; item->line_style = 1; g_queue_push_tail(seq_info->items, item); return (TRUE); }
static const gchar *gen_olc_key(guint16 lc_num, address *dst_addr, address *src_addr) { return ep_strdup_printf("%s/%s/%u", address_to_str(dst_addr), address_to_str(src_addr), lc_num); }