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>
This commit is contained in:
parent
268841f3e0
commit
b682bbd6ee
|
@ -1474,6 +1474,7 @@ libwireshark.so.0 libwireshark0 #MINVER#
|
||||||
tvb_ensure_bytes_exist64@Base 1.99.0
|
tvb_ensure_bytes_exist64@Base 1.99.0
|
||||||
tvb_ensure_captured_length_remaining@Base 1.12.0~rc1
|
tvb_ensure_captured_length_remaining@Base 1.12.0~rc1
|
||||||
tvb_find_guint8@Base 1.9.1
|
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@Base 1.9.1
|
||||||
tvb_find_line_end_unquoted@Base 1.9.1
|
tvb_find_line_end_unquoted@Base 1.9.1
|
||||||
tvb_find_tvb@Base 1.9.1
|
tvb_find_tvb@Base 1.9.1
|
||||||
|
|
|
@ -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);
|
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
|
static inline gint
|
||||||
tvb_ws_mempbrk_guint8_generic(tvbuff_t *tvb, guint abs_offset, guint limit, const ws_mempbrk_pattern* pattern, guchar *found_needle)
|
tvb_ws_mempbrk_guint8_generic(tvbuff_t *tvb, guint abs_offset, guint limit, const ws_mempbrk_pattern* pattern, guchar *found_needle)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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,
|
WS_DLL_PUBLIC gint tvb_find_guint8(tvbuff_t *tvb, const gint offset,
|
||||||
const gint maxlength, const guint8 needle);
|
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
|
/** 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"
|
* tvbuff, starting at offset. The passed in pattern must have been "compiled"
|
||||||
|
|
Loading…
Reference in New Issue