Logo Search packages:      
Sourcecode: wireshark version File versions

gint tvb_find_tvb ( tvbuff_t *  haystack_tvb,
tvbuff_t *  needle_tvb,
gint  haystack_offset 
)

Locate a sub-tvbuff within another tvbuff, starting at position 'haystack_offset'. Returns the index of the beginning of 'needle' within 'haystack', or -1 if 'needle' is not found. The index is relative to the start of 'haystack', not 'haystack_offset'.

Definition at line 2664 of file tvbuff.c.

{
      guint       haystack_abs_offset, haystack_abs_length;
      const guint8      *haystack_data;
      const guint8      *needle_data;
      const guint       needle_len = needle_tvb->length;
      const guint8      *location;

      if (haystack_tvb->length < 1 || needle_tvb->length < 1) {
            return -1;
      }

      /* Get pointers to the tvbuffs' data. */
      haystack_data = tvb_get_ptr(haystack_tvb, 0, -1);
      needle_data = tvb_get_ptr(needle_tvb, 0, -1);

      check_offset_length(haystack_tvb, haystack_offset, -1,
                  &haystack_abs_offset, &haystack_abs_length);

      location = epan_memmem(haystack_data + haystack_abs_offset, haystack_abs_length,
                  needle_data, needle_len);

      if (location) {
            return location - haystack_data;
      }
      else {
            return -1;
      }

      return -1;
}


Generated by  Doxygen 1.6.0   Back to index