diff options
author | Guy Harris <guy@alum.mit.edu> | 2001-07-02 07:11:40 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2001-07-02 07:11:40 +0000 |
commit | db5e1b8c857e1b4866547efce72f6a09af9a3076 (patch) | |
tree | 90b42bb9849ef3e3ebf9768c307afb601d97d14a /epan | |
parent | e78964cea031762e6c7cae3334fcd21eff7091fd (diff) |
Tvbuffify the DNS, NBNS, NBDS, and NBSS dissectors.
Add a "tvb_memeql()" routine, for doing "memcmp()"-style equality
comparisons.
svn path=/trunk/; revision=3631
Diffstat (limited to 'epan')
-rw-r--r-- | epan/tvbuff.c | 39 | ||||
-rw-r--r-- | epan/tvbuff.h | 18 |
2 files changed, 51 insertions, 6 deletions
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 <gram@xiexie.org> * @@ -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) { @@ -1266,6 +1272,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 ... */ diff --git a/epan/tvbuff.h b/epan/tvbuff.h index d008fb1145..794c998a7f 100644 --- a/epan/tvbuff.h +++ b/epan/tvbuff.h @@ -9,7 +9,7 @@ * the data of a backing tvbuff, or can be a composite of * other tvbuffs. * - * $Id: tvbuff.h,v 1.13 2001/05/27 21:34:05 guy Exp $ + * $Id: tvbuff.h,v 1.14 2001/07/02 07:11:40 guy Exp $ * * Copyright (c) 2000 by Gilbert Ramirez <gram@xiexie.org> * @@ -351,13 +351,25 @@ gint tvb_find_line_end(tvbuff_t *tvb, gint offset, int len, gint *eol); gint tvb_find_line_end_unquoted(tvbuff_t *tvb, gint offset, int len, gint *next_offset); -/* 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); -/* 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); /* + * 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); + +/* * Format a bunch of data from a tvbuff as bytes, returning a pointer * to the string with the formatted data. */ |