Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Ethereal-dev: RE: [Ethereal-dev] Create new tvbuff

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Jeff Foster <jfoste@xxxxxxxxxxxx>
Date: Fri, 30 Mar 2001 16:22:06 -0600
From: Frank Singleton [mailto:frank.singleton@xxxxxxxxxxxx]
Sent: Friday, March 30, 2001 3:36 PM


> Anyway, I want to  create a new tvbuff from this octet stream,
> so I can leverage my existing get_CDR_xxx(tvbuff * ..)
> routines to pull it to pieces, and process parts of the IOR.
>
> I would appreciate some input on how a subdissector can
> create tvbuff  properly, and dispose of it when required, and
> what overhead that creates in ethereal.

If I read this right and you are decoding the data to create a
new data set. You should check the code in packet-wcp.c.  In
the wcp_uncompress routine, around line 858, it goes something
like this -


        TRY {		/* create the new tvbuffer with your data */
                tvb = tvb_new_real_data( data, len, len, "DataName");
		
        }
        CATCH(BoundsError) {
                g_assert_not_reached();
		g_free(buf);
		return NULL;
        }
        CATCH(ReportedBoundsError) {
 		g_free(buf);
               return NULL;
        }
        ENDTRY; 

	/* Link the new tvbuffer to old tvbuffer, so cleanup works */
	tvb_set_child_real_data_tvbuff( src_tvb, tvb);

	/* Add new data to the data source list */
	pinfo->fd->data_src = g_slist_append( pinfo->fd->data_src, tvb);


This assumes that you do the real data buffer cleanup yourself.
It you want the tvbuffer to handle cleanup of your data buffer, you 
should call the tvb_set_free_cb fucntion to add a cleanup callback
routine.


Jeff Foster
jfoste@xxxxxxxxxxxx