Logo Search packages:      
Sourcecode: wireshark version File versions  Download package

const guint8* epan_memmem ( const guint8 *  haystack,
guint  haystack_len,
const guint8 *  needle,
guint  needle_len 
)

Return the first occurrence of needle in haystack. Algorithm copied from GNU's glibc 2.3.2 memcmp()

Parameters:
haystack The data to search
haystack_len The length of the search data
needle The string to look for
needle_len The length of the search string
Returns:
A pointer to the first occurrence of "needle" in "haystack". If "needle" isn't found or is NULL, or if "needle_len" is 0, NULL is returned.

Definition at line 825 of file strutil.c.

{
      const guint8 *begin;
      const guint8 *const last_possible
            = haystack + haystack_len - needle_len;

      if (needle_len == 0) {
            return NULL;
      }

      if (needle_len > haystack_len) {
            return NULL;
      }

      for (begin = haystack ; begin <= last_possible; ++begin) {
            if (begin[0] == needle[0] &&
                  !memcmp(&begin[1], needle + 1,
                        needle_len - 1)) {
                  return begin;
            }
      }

      return NULL;
}


Generated by  Doxygen 1.6.0   Back to index