From db5e1b8c857e1b4866547efce72f6a09af9a3076 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 2 Jul 2001 07:11:40 +0000 Subject: Tvbuffify the DNS, NBNS, NBDS, and NBSS dissectors. Add a "tvb_memeql()" routine, for doing "memcmp()"-style equality comparisons. svn path=/trunk/; revision=3631 --- epan/tvbuff.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'epan/tvbuff.c') diff --git a/epan/tvbuff.c b/epan/tvbuff.c index 738ce2dc19..f98358271a 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -9,7 +9,7 @@ * the data of a backing tvbuff, or can be a composite of * other tvbuffs. * - * $Id: tvbuff.c,v 1.17 2001/05/27 21:34:05 guy Exp $ + * $Id: tvbuff.c,v 1.18 2001/07/02 07:11:40 guy Exp $ * * Copyright (c) 2000 by Gilbert Ramirez * @@ -1217,7 +1217,10 @@ tvb_strnlen(tvbuff_t *tvb, gint offset, guint maxlength) * Implement strneql etc */ -/* Call strncmp after checking if enough chars left, otherwise return -1 */ +/* + * Call strncmp after checking if enough chars left, returning 0 if + * it returns 0 (meaning "equal") and -1 otherwise, otherwise return -1. + */ gint tvb_strneql(tvbuff_t *tvb, gint offset, const guint8 *str, gint size) { @@ -1241,7 +1244,10 @@ tvb_strneql(tvbuff_t *tvb, gint offset, const guint8 *str, gint size) } } -/* Call strncasecmp after checking if enough chars left, otherwise return -1 */ +/* + * Call strncasecmp after checking if enough chars left, returning 0 if + * it returns 0 (meaning "equal") and -1 otherwise, otherwise return -1. + */ gint tvb_strncaseeql(tvbuff_t *tvb, gint offset, const guint8 *str, gint size) { @@ -1265,6 +1271,33 @@ tvb_strncaseeql(tvbuff_t *tvb, gint offset, const guint8 *str, gint size) } } +/* + * Call memcmp after checking if enough chars left, returning 0 if + * it returns 0 (meaning "equal") and -1 otherwise, otherwise return -1. + */ +gint +tvb_memeql(tvbuff_t *tvb, gint offset, const guint8 *str, gint size) +{ + guint8 *ptr; + + ptr = ensure_contiguous(tvb, offset, size); + + if (ptr) { + int cmp = memcmp(ptr, str, size); + + /* + * Return 0 if equal, -1 otherwise. + */ + return (cmp == 0 ? 0 : -1); + } else { + /* + * Not enough characters in the tvbuff to match the + * string. + */ + return -1; + } +} + /* * Format the data in the tvb from offset for length ... */ -- cgit v1.2.3