Ethereal-dev: Re: [ethereal-dev] Dissector exceptions

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

From: Gilbert Ramirez <gram@xxxxxxxxxx>
Date: Tue, 09 May 2000 08:55:23 -0500
On Tue, May 09, 2000 at 11:22:33AM +0200, andreas.sikkema@xxxxxxxxxxx wrote:
> > 	(that is, bits 6-7 in byte 2, and bits 0-2 in byte 1, if you
> >	consider the 16 bits in bytes 1 and 2 to be a single unit (like an
> >	endian-independent uint16), and to count bits from the right)
> 
> No, read the bits in the order that they appear.
> 
> Example
> 	03 80 00 00 00 00 02 FF FF
> 
> Suppose the protocol defined for the example is defined as:
> 	Type:              6 bits
> 	Subtype:           3 bits
> 	Padding character: 7 bits
> 	Padding length:    8 bits
> 	Data length:       32 bits
> 	Data:              Data length bytes
> 	Padding:           Padding length bytes
> 
> What I was thinking about was to retrieve those values like this:
> int type      = tvbuff_get_bits( tvbf, 6 );
> int subtype   = tvbuff_get_bits( tvbf, 3 );
> char pad_char = tvbuff_get_bits( tvbf, 7 );
> int plength   = tv_buff_get_byte( tvbf );
> int dlen      = tv_buff_get_bits( tvbf, 32 );
> char* pdata   = tv_buff_get_bytes( tvbf, pdata, dlen );

Interesting. I never though to make the tvbuff accessors work sequentially
instead of in a random-access fashion. But I'd like to create a
tvbuff-cursor or iterator to keep track of the current position, rather
than store that in the tvbuff itself. The cursor can keep a pointer to
the tvbuff:

tvbuff_cursor_t tvbc	= tvbuff_create_cursor(tvbf)
int type      		= tvbc_get_bits( tvbc, 6 );
int subtype   		= tvbc_get_bits( tvbc, 3 );
char pad_char 		= tvbc_get_bits( tvbc, 7 );
int plength   		= tvbc_get_bits( tvbc, 8 );
int dlen      		= tvbc_get_bits( tvbc, 32 );
char* pdata   		= tvbc_get_bits( tvbc, dlen * 8);

--gilbert