summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/libwireshark0.symbols1
-rw-r--r--epan/tvbuff.c42
-rw-r--r--epan/tvbuff.h3
3 files changed, 46 insertions, 0 deletions
diff --git a/debian/libwireshark0.symbols b/debian/libwireshark0.symbols
index 2fa8168ab4..299a635703 100644
--- a/debian/libwireshark0.symbols
+++ b/debian/libwireshark0.symbols
@@ -1474,6 +1474,7 @@ libwireshark.so.0 libwireshark0 #MINVER#
tvb_ensure_bytes_exist64@Base 1.99.0
tvb_ensure_captured_length_remaining@Base 1.12.0~rc1
tvb_find_guint8@Base 1.9.1
+ tvb_find_guint16@Base 2.3.0
tvb_find_line_end@Base 1.9.1
tvb_find_line_end_unquoted@Base 1.9.1
tvb_find_tvb@Base 1.9.1
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)
{
diff --git a/epan/tvbuff.h b/epan/tvbuff.h
index c52e3b03f1..4ceb5a000e 100644
--- a/epan/tvbuff.h
+++ b/epan/tvbuff.h
@@ -497,6 +497,9 @@ WS_DLL_PUBLIC const guint8 *tvb_get_ptr(tvbuff_t *tvb, const gint offset,
WS_DLL_PUBLIC gint tvb_find_guint8(tvbuff_t *tvb, const gint offset,
const gint maxlength, const guint8 needle);
+/** Same as tvb_find_guint8() with 16bit needle. */
+WS_DLL_PUBLIC gint tvb_find_guint16(tvbuff_t *tvb, const gint offset,
+ const gint maxlength, const guint16 needle);
/** Find first occurrence of any of the needles of the pre-compiled pattern in
* tvbuff, starting at offset. The passed in pattern must have been "compiled"