Ethereal-dev: [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: Richard Sharpe <sharpe@xxxxxxxxxx>
Date: Thu, 07 Sep 2000 01:07:06 +0900
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.


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