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] tvbuff questions and conclusions...

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

From: Gilbert Ramirez <gilramir@xxxxxxxxx>
Date: Mon, 12 Mar 2001 10:31:33 -0600
Diwakar Shetty wrote:
> 
> hi
> 
> In order to transfer the existing code from 0.8.9 to 0.8.16......i went
> through the tvbuff.c and tvbuff.h files to understand the working of
> tvbuff. This had to be done because personally I found the documentation
> about the interfaces to tvbuff (in tvbuff.h) to be not that thorough
> which I expected...

Really? Hmm, tvbuff.h is probably some of the best documentation on APIs
that we have. :) Did you read doc/README.tvbuff, too?  
What aspects of the documentation do you feel need better explanation?

> 
> so I have come to some conclusions and also some doubths....
> 
> please let me know if i am wrong in the conclusions....
> 
> Conclusion No. 1: traversal down the tvb tree is done by the "used_in"
> field of "struct tvbuff"

Yes. Note that dissectors will never need to traverse the tvbuff tree, 
but if tvbuff code needed to do that, then yes.

> 
> Conclusion No. 2: traversal up the tvb tree is done by the "subset"
> field of "struct tvbuff"

Yes. Or more correctly, through either member of the "tvbuffs" union.

 
> Doubth No.1  : Why two "len" fields are required (one of which is in
> "struct tvbuff" and another in the "subset" field of "struct tvbuff") .
> I am asking because both of them are set to the same value in the
> function "tvb_set_subset()"

I think the length in tvb_backing_t was just garbage that got left over
during the initial implementation of tvbuffs. Thanks for pointing that
out.

> 
> Doubth No. 2 : Why is  "used_in" field of "struct tvbuff" a pointer to a
> list. Shouldn't it be just a pointer to "struct tvbuff". I am asking
> because upon going through the code , one finds that "used_in" points
> just to one entry i.e the "new_subset".

A tvbuff can be used in more than one other tvbuff. We don't yet do that
in Ethereal, but it's possible.  For example, if for some reason you
needed
to make to separate TVBUFF_SUBSETs from a tvbuff, then:

		TVBUFF_REAL_DATA
			|
			|
		TVBUFF_SUBSET
			|
			|
		TVBUFF_SUBSET
			|\
			| \
			|  \----+
			|	|
		TVBUFF_SUBSET	TVBUFF_SUBSET


Since the tvbuff routines are responsible for reference counting and
freeing memory when a tvbuff is no longer used, a tvbuff needs to know
all other tvbuffs in which it is used so that it can propagate
the reference-count decrement.
 
--gilbert