Ethereal-dev: Re: [Ethereal-dev] Some TVB rountines I want to add ...

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

From: Guy Harris <gharris@xxxxxxxxxxxx>
Date: Tue, 28 Nov 2000 00:58:39 -0800
On Tue, Nov 28, 2000 at 01:50:28PM +1000, Richard Sharpe wrote:
> 1. tvb_skip_bytes
>    
>    int
>    tvb_skip_bytes(tvbuff_t *tvb, guint offset, guint8 bytes[], 
>                   guint len, guint min, guint max)
> 
>    Returns -1 if the specified (len of bytes)*min does not occur at 
>    the currentoffset, or there is not enough characters in the buffer.
> 
>    Returns number of bytes skipped if (len bytes)*min found in buffer, up to
>    (len bytes)*max.  Only complete occurrences of (len bytes) skipped. Any
>    partial initial match does not count!
>  
>    This does not currently seem to exist as a routine.

What does it skip over? Occurrences of the exact "len"-byte array of
bytes "bytes"?

Where would that be used?

> 2. ptvcursor_get_item_[guint8, guint16, guint32, gint8, gint16, gint32 etc]
>  
>    int
>    ptvcursor_get_item_guint8(tvbuff_t *tvb, guint offset, 
> 				  guint min, guint max, void *item)
> 
>    Look for a string of characters that is convertable to an item of the
>    specified type and convert to the specified item.

I assume "convertable" means "convertable as text", e.g. "1234" can be
converted to a g{u}int16 or g{u}int32 with the value 1234.

If so, I'm not sure 8-bit or 16-bit versions are necessary - the
underlying data in the packet is a text string, so it's not meaningful
to say it's "8 bits" or "16 bits" or "32 bits" worth of number (it could
be 8, or 16, or 24, or 32, or 40, or... bits worth of *characters*, but
that's another matter).

I'd thus be inclined to call them "ptvcursor_get_int" and
"ptvcursor_get_uint"...

...but I'm not sure why it's ptvcursor-specific; it takes a "tvbuff_t *"
rather than a "ptvcursor_t *" as an argument, so I'd be tempted to call
them just "tvbuff_get_int" and "tvbuff_get_uint" or something such as
that.

>    Return item in item, and return chars consumed in return value or -1
>    if specified item not found.

I assume "specified item not found" includes "string isn't numeric".

>    If not enough characters in buffer for min, return -1.

Why return -1 rather than throwing an exception?  If it returns -1,
you'd want it to somehow indicate whether there weren't enough
characters or if there were but they weren't numeric.

Should it also allow a number base to be specified?