Ethereal-dev: Re: [ethereal-dev] String comparisons with tvb

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: Thu, 7 Sep 2000 02:02:21 -0400
On Thu, Sep 07, 2000 at 01:07:06AM +0900, Richard Sharpe wrote:
> Hi,
> 
> I am tvbuffifying the BXXP dissector, and have a need to do string
> comparisons.
> 
> However, my only need is to compare strings for equality.
> 
> I initially thought of trying to implement tvb_strncmp, but that raises
> some big issues.
> 
> In particular, if the tvbuff does not contain enough characters, returning
> a sensible value from tvb_strncmp becomes difficult (eg, if buff contains
> BU at the end, and you are comparing to BUFF, what do you return? While -1
> seems OK, that implies that you have to actually do a partial check.
> 
> So, I was thinking of 
> 
>   tvb_strneql(tvbuff_t *tvb, gint offset, guint8 *str, gint size)
>     return val == 0 if equal, -1 if not or not enought chars.
> 
> It would check if enough characters, if not return -1, else call strncmp,
> and if result not 0, return -1.

There's no harm in postponing the harder decision of tvb_strncmp()
and just implementing tvb_strneql() for now.

--gilbert