diff options
author | krj <krj@f5534014-38df-0310-8fa8-9805f1628bb7> | 2009-08-15 06:38:10 +0000 |
---|---|---|
committer | krj <krj@f5534014-38df-0310-8fa8-9805f1628bb7> | 2009-08-15 06:38:10 +0000 |
commit | a268b29164b24eaff97efc8fc57a8e7e71c1ce54 (patch) | |
tree | a46ff02b744f06032eaef2a29c3777ff4d894226 | |
parent | 1a3d31f474abacfda8358735a3e78bc516c9cdec (diff) |
This patch introduces packet_add_new_data_source() which effectively deprecates add_new_data_source(). This is based on the following observation:
1) The tvb + name (aka. data_source) is only used when the protocol tree is visible
The current implementation of add_new_data_source() doesn't take this into account and simply allocates a data_source regardless. This is what packet_add_new_data_source() tries to rectify.
A couple of dissectors have already been switched over to the new packet_add_new_data_source(). Many are still missing. Help appreciated!
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@29427 f5534014-38df-0310-8fa8-9805f1628bb7
-rw-r--r-- | epan/dissectors/packet-bthci_acl.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-btl2cap.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-btrfcomm.c | 2 | ||||
-rw-r--r-- | epan/packet.c | 15 | ||||
-rw-r--r-- | epan/packet.h | 15 | ||||
-rw-r--r-- | epan/reassemble.c | 2 | ||||
-rw-r--r-- | epan/reassemble_test.c | 4 | ||||
-rw-r--r-- | epan/wslua/wslua_dumper.c | 15 | ||||
-rw-r--r-- | print.c | 8 |
9 files changed, 51 insertions, 14 deletions
diff --git a/epan/dissectors/packet-bthci_acl.c b/epan/dissectors/packet-bthci_acl.c index df4878802b..5a1ccb3bf3 100644 --- a/epan/dissectors/packet-bthci_acl.c +++ b/epan/dissectors/packet-bthci_acl.c @@ -212,7 +212,7 @@ dissect_btacl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) } if(mfp && mfp->last_frame==pinfo->fd->num){ next_tvb = tvb_new_child_real_data(tvb, (guint8*)mfp->reassembled, mfp->tot_len, mfp->tot_len); - add_new_data_source(pinfo, next_tvb, "Reassembled BTHCI ACL"); + packet_add_new_data_source(pinfo, btacl_tree, next_tvb, "Reassembled BTHCI ACL"); /* call L2CAP dissector */ if(btl2cap_handle){ diff --git a/epan/dissectors/packet-btl2cap.c b/epan/dissectors/packet-btl2cap.c index 95aeee9c4e..004d1f7786 100644 --- a/epan/dissectors/packet-btl2cap.c +++ b/epan/dissectors/packet-btl2cap.c @@ -934,7 +934,7 @@ static void dissect_i_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, } if(segment == 0x02 && mfp && mfp->last_frame==pinfo->fd->num){ next_tvb = tvb_new_child_real_data(tvb, (guint8*)mfp->reassembled, mfp->tot_len, mfp->tot_len); - add_new_data_source(pinfo, next_tvb, "Reassembled L2CAP"); + packet_add_new_data_source(pinfo, btl2cap_tree, next_tvb, "Reassembled L2CAP"); } /*pass up to higher layer if we have a complete packet*/ if(segment == 0x00) { diff --git a/epan/dissectors/packet-btrfcomm.c b/epan/dissectors/packet-btrfcomm.c index 56ac766273..0d1d0efa65 100644 --- a/epan/dissectors/packet-btrfcomm.c +++ b/epan/dissectors/packet-btrfcomm.c @@ -760,7 +760,7 @@ dissect_btrfcomm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) for (p = rps->ppp_first; p; p = p->next) { next_tvb = tvb_new_child_real_data(tvb, (guint8 *) (p + 1), p->len, p->len); - add_new_data_source(pinfo, next_tvb, "Reassembled PPP frame"); + packet_add_new_data_source(pinfo, rfcomm_tree, next_tvb, "Reassembled PPP frame"); call_dissector(ppp_handle, next_tvb, pinfo, tree); } } else { diff --git a/epan/packet.c b/epan/packet.c index 280e86a687..b056d391a1 100644 --- a/epan/packet.c +++ b/epan/packet.c @@ -202,6 +202,13 @@ add_new_data_source(packet_info *pinfo, tvbuff_t *tvb, const char *name) pinfo->data_src = g_slist_append(pinfo->data_src, src); } +void +packet_add_new_data_source(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, const char *name) +{ + if (tree && PTREE_DATA(tree)->visible) + add_new_data_source(pinfo, tvb, name); +} + const char* get_data_source_name(data_source *src) { @@ -219,8 +226,10 @@ get_data_source_name(data_source *src) void free_data_sources(packet_info *pinfo) { - g_slist_free(pinfo->data_src); - pinfo->data_src = NULL; + if (pinfo->data_src) { + g_slist_free(pinfo->data_src); + pinfo->data_src = NULL; + } } /* Allow dissectors to register a "final_registration" routine @@ -288,7 +297,7 @@ dissect_packet(epan_dissect_t *edt, union wtap_pseudo_header *pseudo_header, TRY { edt->tvb = tvb_new_real_data(pd, fd->cap_len, fd->pkt_len); /* Add this tvbuffer into the data_src list */ - add_new_data_source(&edt->pi, edt->tvb, "Frame"); + packet_add_new_data_source(&edt->pi, edt->tree, edt->tvb, "Frame"); /* Even though dissect_frame() catches all the exceptions a * sub-dissector can throw, dissect_frame() itself may throw diff --git a/epan/packet.h b/epan/packet.h index 5725b58dd5..50b8f7965f 100644 --- a/epan/packet.h +++ b/epan/packet.h @@ -377,11 +377,22 @@ extern void final_registration_all_protocols(void); /* + * DEPRECATED: Use packet_add_new_data_source() instead. + */ +extern void +add_new_data_source(packet_info *pinfo, tvbuff_t *tvb, const char *name); + +/* * Add a new data source to the list of data sources for a frame, given * the tvbuff for the data source and its name. + * + * @param tree The protocol tree. + * @param pinfo Packet Info. + * @param tvb The buffer to store. + * @param name The name of the data source */ -extern void add_new_data_source(packet_info *pinfo, tvbuff_t *tvb, - const char *name); +extern void +packet_add_new_data_source(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, const char *name); /* * Return the data source name. diff --git a/epan/reassemble.c b/epan/reassemble.c index 471651a179..086910307e 100644 --- a/epan/reassemble.c +++ b/epan/reassemble.c @@ -1836,7 +1836,7 @@ process_reassembled_data(tvbuff_t *tvb, int offset, packet_info *pinfo, tvb_set_child_real_data_tvbuff(tvb, next_tvb); /* Add the defragmented data to the data source list. */ - add_new_data_source(pinfo, next_tvb, name); + packet_add_new_data_source(pinfo, tree, next_tvb, name); /* show all fragments */ if (fd_head->flags & FD_BLOCKSEQUENCE) { diff --git a/epan/reassemble_test.c b/epan/reassemble_test.c index e5e745f18d..828726a215 100644 --- a/epan/reassemble_test.c +++ b/epan/reassemble_test.c @@ -1062,6 +1062,10 @@ void add_new_data_source(packet_info *pinfo _U_, tvbuff_t *tvb _U_, const char *name _U_) {} +void packet_add_new_data_source(packet_info *pinfo _U_, proto_tree *tree _U_, tvbuff_t *tvb _U_, + const char *name _U_) +{} + proto_item * proto_tree_add_uint(proto_tree *tree _U_, int hfindex _U_, tvbuff_t *tvb _U_, gint start _U_, gint length _U_, guint32 value _U_) diff --git a/epan/wslua/wslua_dumper.c b/epan/wslua/wslua_dumper.c index 909244f738..e7bd4221df 100644 --- a/epan/wslua/wslua_dumper.c +++ b/epan/wslua/wslua_dumper.c @@ -351,22 +351,27 @@ WSLUA_METHOD Dumper_dump_current(lua_State* L) { Dumper d = checkDumper(L,1); struct wtap_pkthdr pkthdr; const guchar* data; - tvbuff_t* data_src; + tvbuff_t* tvb; + data_source *data_src; int err = 0; if (!d) return 0; if (! lua_pinfo ) WSLUA_ERROR(Dumper_new_for_current,"Cannot be used outside a tap or a dissector"); - data_src = ((data_source*)(lua_pinfo->data_src->data))->tvb; + data_src = (data_source*) (lua_pinfo->data_src->data); + if (!data_src) + return 0; + + tvb = data_src->tvb; pkthdr.ts.secs = lua_pinfo->fd->abs_ts.secs; pkthdr.ts.nsecs = lua_pinfo->fd->abs_ts.nsecs; - pkthdr.len = tvb_reported_length(data_src); - pkthdr.caplen = tvb_length(data_src); + pkthdr.len = tvb_reported_length(tvb); + pkthdr.caplen = tvb_length(tvb); pkthdr.pkt_encap = lua_pinfo->fd->lnk_t; - data = ep_tvb_memdup(data_src,0,pkthdr.caplen); + data = ep_tvb_memdup(tvb,0,pkthdr.caplen); if (! wtap_dump(d, &pkthdr, lua_pinfo->pseudo_header, data, &err)) { luaL_error(L,"error while dumping: %s", @@ -240,6 +240,10 @@ proto_tree_write_pdml(epan_dissect_t *edt, FILE *fh) data.src_list = edt->pi.data_src; data.edt = edt; + /* We shouldn't be called with a NULL pointer here because we've + * created a visible protocol tree */ + g_assert(data.src_list); + fprintf(fh, "<packet>\n"); /* Print a "geninfo" protocol as required by PDML */ @@ -776,6 +780,10 @@ print_hex_data(print_stream_t *stream, epan_dissect_t *edt) const guchar *cp; guint length; + /* We shouldn't be called with a NULL pointer here because we've + * created a visible protocol tree */ + g_assert(edt->pi.data_src); + /* * Set "multiple_sources" iff this frame has more than one * data source; if it does, we need to print the name of |