Wireshark-dev: [Wireshark-dev] [Patch] epan_strcasestr() to epan/strutil.c

From: Gisle Vanem <gvanem@xxxxxxxxxxxx>
Date: Wed, 07 Feb 2007 14:11:02 +0100
The file epan/dissectors/packet-k12.c uses the function
strcasestr() which is not available on e.g. Windows. So I cooked
up a patch to epan/strutil.c to add epan_strcasestr() (is there a more suited place for such a function?)

Attached in diffs-3.txt

--gv
--- SVN-Latest\epan\strutil.c	Mon Feb 05 12:13:00 2007
+++ epan\strutil.c	Wed Feb 07 13:49:17 2007
@@ -966,3 +966,17 @@
	return strl+strs;
}
#endif
+
+char *
+epan_strcasestr(const char *haystack, const char *needle)
+{
+	gsize hlen = strlen(haystack);
+	gsize nlen = strlen(needle);
+
+	while (hlen-- >= nlen) {
+		if (!g_strncasecmp(haystack, needle, nlen))
+			return (char*) haystack;
+		haystack++;
+	}
+	return NULL;
+}
--- SVN-Latest\epan\strutil.h	Fri Jan 12 17:23:56 2007
+++ epan\strutil.h	Wed Feb 07 13:44:40 2007
@@ -205,6 +205,16 @@
 */
char * convert_string_case(const char *string, gboolean case_insensitive);

+/** Finds the first occurence of string 'needle' in string 'haystack'.
+ *  The matching is done in a case insensitive manner.
+ *
+ * @param haystack The string possibly containing the substring
+ * @param needle The substring to be searched
+ * @return A pointer into 'haystack' where 'needle' is first found.
+ *   Otherwise it returns NULL.
+ */
+char * epan_strcasestr(const char *haystack, const char *needle);
+
/* g_strlcat() does not exist in GLib 1.2[.x] */
#if GLIB_MAJOR_VERSION < 2
gsize g_strlcat(gchar *dst, gchar *src, gsize size);
--- SVN-Latest\epan\libwireshark.def	Mon Feb 05 12:12:57 2007
+++ epan\libwireshark.def	Wed Feb 07 13:48:25 2007
@@ -245,6 +245,7 @@
epan_get_version
epan_init
epan_base64_decode
+epan_strcasestr
ether_to_str
ex_opt_add
ex_opt_count
--- SVN-Latest\epan\dissectors\packet-k12.c	Mon Feb 05 12:13:00 2007
+++ epan\dissectors\packet-k12.c	Wed Feb 07 13:29:10 2007
@@ -38,6 +38,7 @@
#include <epan/emem.h>
#include <epan/uat.h>
#include <epan/expert.h>
+#include <epan/strutil.h>
#include "packet-sscop.h"

typedef struct _k12_hdls_t {
@@ -135,7 +136,7 @@
	
	if (! handles ) {
		for (i=0 ; i < nk12_handles; i++) {
-			if ( strcasestr(pinfo->pseudo_header->k12.stack_file, k12_handles[i].match) ) {
+			if ( epan_strcasestr(pinfo->pseudo_header->k12.stack_file, k12_handles[i].match) ) {
				handles = k12_handles[i].handles;
				break;
			}