Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Ethereal-users: [Ethereal-users] updated net-snmp/ethereal patch

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Wes Hardaker <wjhns36@xxxxxxxxxxxxx>
Date: Tue, 22 Oct 2002 12:23:17 -0700
After working with Joerg Mayer, who found a few ucd-snmp specific bugs
with respect to the last patch I submitted, I've got a new one to be
used in place of the previous one:
-- 
Wes Hardaker
Network Associates Laboratories
? config.out
? ethereal-net-snmp.patch
? new-configure.patch
? testcpp
Index: AUTHORS
===================================================================
RCS file: /cvsroot/ethereal/AUTHORS,v
retrieving revision 1.646
diff -u -r1.646 AUTHORS
--- AUTHORS	2002/10/22 08:47:44	1.646
+++ AUTHORS	2002/10/22 19:21:33
@@ -469,8 +469,9 @@
 	Additional NTP reference clock identifiers
 }
 
-Wes Hardaker <wjhardaker[AT]ucdavis.edu> {
+Wes Hardaker <hardaker[AT]users.sourceforge.net> {
 	Kerberos 5 support
+	occasional ucd-snmp/net-snmp help.
 }
 
 Robert Tsai <rtsai[AT]netapp.com> {
Index: acconfig.h
===================================================================
RCS file: /cvsroot/ethereal/acconfig.h,v
retrieving revision 1.25
diff -u -r1.25 acconfig.h
--- acconfig.h	2002/08/28 21:00:05	1.25
+++ acconfig.h	2002/10/22 19:21:33
@@ -44,6 +44,8 @@
 
 #undef HAVE_LIBZ
 
+#undef HAVE_NET_SNMP
+
 #undef HAVE_UCD_SNMP
 
 #undef PLUGIN_DIR
Index: configure.in
===================================================================
RCS file: /cvsroot/ethereal/configure.in,v
retrieving revision 1.182
diff -u -r1.182 configure.in
--- configure.in	2002/10/09 22:58:49	1.182
+++ configure.in	2002/10/22 19:21:34
@@ -540,6 +540,11 @@
 SNMP_LIBS=''
 AC_MSG_CHECKING(whether to use UCD SNMP/NET-SNMP library if available)
 
+AC_ARG_WITH(net-snmp,
+[  --with-net-snmp=PATH  use PATH as thee location of the net-snmp-config shell script that comes with the net-snmp package.],
+[netsnmpconfig=$withval]
+)
+
 AC_ARG_WITH(ucdsnmp,
 [  --with-ucdsnmp[=DIR]    use UCD SNMP/NET-SNMP client library (located in directory DIR, if supplied).  [default=yes, if present]],
 [
@@ -562,12 +567,40 @@
 	ucdsnmp_dir=
 ])
 
-if test "x$want_ucdsnmp" = "xno" ; then
-	AC_MSG_RESULT(no)
+dnl try net-snmp first
+if test "x$netsnmpconfig" != "xno" ; then
+	dnl get the net-snmp-config binary
+	if test "x$netsnmpconfig" = "xyes" -o "x$netsnmpconfig" = "x" ; then
+		dnl search for it
+		AC_PATH_PROG(NETSNMPCONFIG,net-snmp-config)
+	else
+		ac_cv_prog_NETSNMPCONFIG=$netsnmpconfig
+		if test ! -x $ac_cv_prog_NETSNMPCONFIG ; then
+			AC_MSG_ERROR(Invalid net-snmp-config: $ac_cv_prog_NETSNMPCONFIG)
+		fi
+	fi
+fi
+
+if test "x$ac_cv_prog_NETSNMPCONFIG" != "xno" -a "x$ac_cv_prog_NETSNMPCONFIG" != "x" -a -x "$ac_cv_prog_NETSNMPCONFIG" ; then
+	dnl other choices for flags to use here: could also use
+	dnl --prefix or --exec-prefix if you don't want the full list.
+	CFLAGS="$CFLAGS `net-snmp-config --cflags`"
+	CPPFLAGS="$CPPLAGS `net-snmp-config --cflags`"
+	SNMP_LIBS=`net-snmp-config --libs`
+
+	# XXX: make sure we can find net-snmp/net-snmp-config.h
+	# XXX: make sure we can find net-snmp/net-snmp-includes.h
+	AC_DEFINE(HAVE_NET_SNMP)
+	AC_MSG_RESULT(yes (net-snmp))
 else
-	AC_MSG_RESULT(yes)
-	AC_ETHEREAL_UCDSNMP_CHECK
+	if test "x$want_ucdsnmp" = "xno" ; then
+		AC_MSG_RESULT(no)
+	else
+		AC_MSG_RESULT(yes (ucd-snmp))
+		AC_ETHEREAL_UCDSNMP_CHECK
+	fi
 fi
+
 AC_SUBST(SNMP_LIBS)
 
 dnl Checks for typedefs, structures, and compiler characteristics.
@@ -738,10 +771,12 @@
 	zlib_message="yes"
 fi
 
-if test "x$SNMP_LIBS" = "x" ; then
+if test "x$ac_cv_prog_NETSNMPCONFIG" != "xno" -a "x$ac_cv_prog_NETSNMPCONFIG" != "x" -a -x "$ac_cv_prog_NETSNMPCONFIG" ; then
+	snmp_libs_message="yes (net-snmp)"
+elif test "x$SNMP_LIBS" = "x" ; then
 	snmp_libs_message="no"
 else
-	snmp_libs_message="yes"
+	snmp_libs_message="yes (ucd-snmp)"
 fi
 
 echo ""
Index: packet-snmp.c
===================================================================
RCS file: /cvsroot/ethereal/packet-snmp.c,v
retrieving revision 1.96
diff -u -r1.96 packet-snmp.c
--- packet-snmp.c	2002/08/28 21:00:34	1.96
+++ packet-snmp.c	2002/10/22 19:21:35
@@ -6,8 +6,10 @@
  *
  * See RFCs 1901, 1905, and 1906 for SNMPv2c.
  *
- * See RFCs 1905, 1906, 1909, and 1910 for SNMPv2u.
+ * See RFCs 1905, 1906, 1909, and 1910 for SNMPv2u [historic].
  *
+ * See RFCs 2570-2576 for SNMPv3
+ *
  * $Id: packet-snmp.c,v 1.96 2002/08/28 21:00:34 jmayer Exp $
  *
  * Ethereal - Network traffic analyzer
@@ -51,7 +53,12 @@
 #include "etypes.h"
 #include "packet-ipx.h"
 
-#ifdef HAVE_UCD_SNMP
+#if defined(HAVE_UCD_SNMP) || defined(HAVE_NET_SNMP)
+#define HAVE_SOME_SNMP
+#ifdef HAVE_NET_SNMP
+# include <net-snmp/net-snmp-config.h>
+# include <net-snmp/net-snmp-includes.h>
+#else
 # include <ucd-snmp/ucd-snmp-config.h>
 # include <ucd-snmp/asn1.h>
 # include <ucd-snmp/snmp_api.h>
@@ -60,7 +67,12 @@
 # include <ucd-snmp/default_store.h>
 # include <ucd-snmp/read_config.h>
 # include <ucd-snmp/tools.h>
-
+# define netsnmp_ds_set_boolean ds_set_boolean
+# define netsnmp_ds_set_int ds_set_int
+# define NETSNMP_DS_LIBRARY_ID DS_LIBRARY_ID
+# define NETSNMP_DS_LIB_NO_TOKEN_WARNINGS DS_LIB_NO_TOKEN_WARNINGS
+# define NETSNMP_DS_LIB_PRINT_SUFFIX_ONLY DS_LIB_PRINT_SUFFIX_ONLY
+#endif
    /*
     * Define values "sprint_realloc_value()" expects.
     */
@@ -441,7 +453,7 @@
 	int len;
 	unsigned int i;
 	char *buf;
-#ifdef HAVE_UCD_SNMP
+#ifdef HAVE_SOME_SNMP
 	guchar *oid_string;
 	size_t oid_string_len;
 	size_t oid_out_len;
@@ -449,7 +461,7 @@
 
 	result_len = oid_length * 22;
 
-#ifdef HAVE_UCD_SNMP
+#ifdef HAVE_SOME_SNMP
 	/*
 	 * Get the decoded form of the OID, and add its length to the
 	 * length of the result string.
@@ -474,7 +486,7 @@
 		buf += len;
 	}
 
-#ifdef HAVE_UCD_SNMP
+#ifdef HAVE_SOME_SNMP
 	/*
 	 * Append the decoded form of the OID.
 	 */
@@ -485,7 +497,7 @@
 	return result;
 }
 
-#ifdef HAVE_UCD_SNMP
+#ifdef HAVE_SOME_SNMP
 static guchar *
 check_var_length(guint vb_length, guint required_length)
 {
@@ -598,12 +610,12 @@
 static int
 snmp_variable_decode(proto_tree *snmp_tree,
     subid_t *variable_oid
-#ifndef HAVE_UCD_SNMP
+#ifndef HAVE_SOME_SNMP
 	_U_
 #endif
     ,
     guint variable_oid_length
-#ifndef HAVE_UCD_SNMP
+#ifndef HAVE_SOME_SNMP
 	_U_
 #endif
     ,
@@ -628,14 +640,14 @@
 
 	gchar *vb_display_string;
 
-#ifdef HAVE_UCD_SNMP
+#ifdef HAVE_SOME_SNMP
 	struct variable_list variable;
 	long value;
-#else /* HAVE_UCD_SNMP */
+#else /* HAVE_SOME_SNMP */
 	unsigned int i;
 	gchar *buf;
 	int len;
-#endif	/* HAVE_UCD_SNMP */
+#endif	/* HAVE_SOME_SNMP */
 
 	/* parse the type of the object */
 	start = asn1->offset;
@@ -666,7 +678,7 @@
 			return ret;
 		length = asn1->offset - start;
 		if (snmp_tree) {
-#ifdef HAVE_UCD_SNMP
+#ifdef HAVE_SOME_SNMP
 			value = vb_integer_value;
 			variable.val.integer = &value;
 			vb_display_string = format_var(&variable,
@@ -676,12 +688,12 @@
 			    length,
 			    "Value: %s", vb_display_string);
 			free(vb_display_string);
-#else /* HAVE_UCD_SNMP */
+#else /* HAVE_SOME_SNMP */
 			proto_tree_add_text(snmp_tree, asn1->tvb, offset,
 			    length,
 			    "Value: %s: %d (%#x)", vb_type_name,
 			    vb_integer_value, vb_integer_value);
-#endif /* HAVE_UCD_SNMP */
+#endif /* HAVE_SOME_SNMP */
 		}
 		break;
 
@@ -694,7 +706,7 @@
 			return ret;
 		length = asn1->offset - start;
 		if (snmp_tree) {
-#ifdef HAVE_UCD_SNMP
+#ifdef HAVE_SOME_SNMP
 			value = vb_uinteger_value;
 			variable.val.integer = &value;
 			vb_display_string = format_var(&variable,
@@ -704,12 +716,12 @@
 			    length,
 			    "Value: %s", vb_display_string);
 			free(vb_display_string);
-#else /* HAVE_UCD_SNMP */
+#else /* HAVE_SOME_SNMP */
 			proto_tree_add_text(snmp_tree, asn1->tvb, offset,
 			    length,
 			    "Value: %s: %u (%#x)", vb_type_name,
 			    vb_uinteger_value, vb_uinteger_value);
-#endif /* HAVE_UCD_SNMP */
+#endif /* HAVE_SOME_SNMP */
 		}
 		break;
 
@@ -725,7 +737,7 @@
 			return ret;
 		length = asn1->offset - start;
 		if (snmp_tree) {
-#ifdef HAVE_UCD_SNMP
+#ifdef HAVE_SOME_SNMP
 			variable.val.string = vb_octet_string;
 			vb_display_string = format_var(&variable,
 			    variable_oid, variable_oid_length, vb_type,
@@ -734,7 +746,7 @@
 			    length,
 			    "Value: %s", vb_display_string);
 			free(vb_display_string);
-#else /* HAVE_UCD_SNMP */
+#else /* HAVE_SOME_SNMP */
 			/*
 			 * If some characters are not printable, display
 			 * the string as bytes.
@@ -771,7 +783,7 @@
 				    (int)vb_length,
 				    SAFE_STRING(vb_octet_string));
 			}
-#endif /* HAVE_UCD_SNMP */
+#endif /* HAVE_SOME_SNMP */
 		}
 		g_free(vb_octet_string);
 		break;
@@ -794,7 +806,7 @@
 			return ret;
 		length = asn1->offset - start;
 		if (snmp_tree) {
-#ifdef HAVE_UCD_SNMP
+#ifdef HAVE_SOME_SNMP
 			variable.val.objid = vb_oid;
 			vb_display_string = format_var(&variable,
 			    variable_oid, variable_oid_length, vb_type,
@@ -803,13 +815,13 @@
 			    length,
 			    "Value: %s", vb_display_string);
 			free(vb_display_string);
-#else /* HAVE_UCD_SNMP */
+#else /* HAVE_SOME_SNMP */
 			vb_display_string = format_oid(vb_oid, vb_oid_length);
 			proto_tree_add_text(snmp_tree, asn1->tvb, offset,
 			    length,
 			    "Value: %s: %s", vb_type_name, vb_display_string);
 			g_free(vb_display_string);
-#endif /* HAVE_UCD_SNMP */
+#endif /* HAVE_SOME_SNMP */
 		}
 		g_free(vb_oid);
 		break;
@@ -2013,7 +2025,7 @@
 		&ett_secur,
 	};
 
-#ifdef HAVE_UCD_SNMP
+#ifdef HAVE_SOME_SNMP
 	/*
 	 * Suppress warnings about unknown tokens - we aren't initializing
 	 * UCD SNMP in its entirety, we're just initializing the
@@ -2022,13 +2034,15 @@
 	 * pars of the library will not be handled, and we don't want
 	 * the config file reading code to whine about that.
 	 */
-	ds_set_boolean(DS_LIBRARY_ID, DS_LIB_NO_TOKEN_WARNINGS, TRUE);
-	ds_set_int(DS_LIBRARY_ID, DS_LIB_PRINT_SUFFIX_ONLY, 2);
+	netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID,
+                               NETSNMP_DS_LIB_NO_TOKEN_WARNINGS, TRUE);
+	netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID,
+                           NETSNMP_DS_LIB_PRINT_SUFFIX_ONLY, 2);
 	register_mib_handlers();
 	read_premib_configs();
 	init_mib();
 	read_configs();
-#endif /* HAVE_UCD_SNMP */
+#endif /* HAVE_SOME_SNMP */
         proto_snmp = proto_register_protocol("Simple Network Management Protocol",
 	    "SNMP", "snmp");
         proto_smux = proto_register_protocol("SNMP Multiplex Protocol",