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: Richard Sharpe <sharpe@xxxxxxxxxx>
Date: Tue, 28 Nov 2000 22:57:45 +1000
At 12:58 AM 11/28/00 -0800, Guy Harris wrote:
>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"?

Yes. 

>Where would that be used?

In protocols where there are literal text strings, or spaces etc separating
elements, the call would allow me to skip one or more of them. 

Ie, with the appropriate calls, it can skip spaces, or tell me if a ':' was
there and skip it, and so on, and so forth.

>> 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).

Yes, I guess you are right ...

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

I guess I agree.

>...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.

OK. Seems fine with me.

>>    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".

Yes.

>>    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.

OK, I guess that you are right. But I could use -1 for not enough chars,
and -2 for they weren't numeric ... 

>Should it also allow a number base to be specified?

Ummm, that would be useful as well.

Regards
-------
Richard Sharpe, sharpe@xxxxxxxxxx
Samba (Team member, www.samba.org), Ethereal (Team member, www.zing.org)
Contributing author, SAMS Teach Yourself Samba in 24 Hours
Author, Special Edition, Using Samba