aboutsummaryrefslogtreecommitdiffstats
path: root/epan/tvbuff.c
diff options
context:
space:
mode:
authorFrancesco Fondelli <francesco.fondelli@gmail.com>2016-09-16 15:13:44 +0200
committerMichael Mann <mmann78@netscape.net>2016-10-08 03:21:44 +0000
commitb682bbd6ee5b93b45727c85293edce5ced9b337c (patch)
tree9c7693416ca3791be8d6e01319fe8c902cf53bd1 /epan/tvbuff.c
parent268841f3e00b7cf0f16c81dd2b3b952172130b8b (diff)
add tvb_find_guint16() utility
Change-Id: I75c0165948325c2e50918706d8a821411761727b Signed-off-by: Francesco Fondelli <francesco.fondelli@gmail.com> Reviewed-on: https://code.wireshark.org/review/17734 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/tvbuff.c')
-rw-r--r--epan/tvbuff.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/epan/tvbuff.c b/epan/tvbuff.c
index 0936998075..8919131344 100644
--- a/epan/tvbuff.c
+++ b/epan/tvbuff.c
@@ -1893,6 +1893,48 @@ tvb_find_guint8(tvbuff_t *tvb, const gint offset, const gint maxlength, const gu
return tvb_find_guint8_generic(tvb, offset, limit, needle);
}
+/* Same as tvb_find_guint8() with 16bit needle. */
+gint
+tvb_find_guint16(tvbuff_t *tvb, const gint offset, const gint maxlength,
+ const guint16 needle)
+{
+ const guint8 needle1 = ((needle & 0xFF00) >> 8);
+ const guint8 needle2 = ((needle & 0x00FF) >> 0);
+ gint searched_bytes = 0;
+ gint pos = offset;
+
+ do {
+ gint offset1 =
+ tvb_find_guint8(tvb, pos, maxlength - searched_bytes, needle1);
+ gint offset2 = -1;
+
+ if (offset1 == -1) {
+ return -1;
+ }
+
+ searched_bytes = offset1 - pos + 1;
+
+ if ((maxlength != -1) && (searched_bytes >= maxlength)) {
+ return -1;
+ }
+
+ offset2 = tvb_find_guint8(tvb, offset1 + 1, 1, needle2);
+
+ searched_bytes += 1;
+
+ if (offset2 != -1) {
+ if ((maxlength != -1) && (searched_bytes > maxlength)) {
+ return -1;
+ }
+ return offset1;
+ }
+
+ pos = offset1 + 1;
+ } while (pos < maxlength);
+
+ return -1;
+}
+
static inline gint
tvb_ws_mempbrk_guint8_generic(tvbuff_t *tvb, guint abs_offset, guint limit, const ws_mempbrk_pattern* pattern, guchar *found_needle)
{