Re: [PATCH] the attached patch makes NET-SNMP 5.0.x working with PHP.
| From: | Harrie Hazewinkel | Date: | Tue, 10 Sep 2002 10:04:06 +0000 |
| Subject: | Re: [PATCH] the attached patch makes NET-SNMP 5.0.x working with PHP. | ||
| References: | 1 2 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-88125@lists.php.net to get a copy of this message | ||
Hi,
Weird but true, somehow the attachment was stripped of somewhere.
It is below inline between the '=' lines.
--On Tuesday, September 10, 2002 12:04 PM +0200 derick@php.net wrote:
Hey, nothing is attached, can you put it on a website? Derick On Tue, 10 Sep 2002, Harrie Hazewinkel wrote:=========================================================================== === diff -ru ../orig-php-4.2.2/ext/snmp/config.m4 ext/snmp/config.m4HI, The attached patch adds an extra configure directive to enable compilation of PHP against NET-SNMP 5.0.x versions. The current UCD-SNMP support is still there, since those version are around still. if it can be added to CVS would be grate. regards,
--- ../orig-php-4.2.2/ext/snmp/config.m4 Wed Jan 16 23:32:40 2002+++ ext/snmp/config.m4 Mon Sep 9 17:57:49 2002 @@ -2,8 +2,8 @@ dnl $Id: config.m4,v 1.24 2002/01/16 22:32:40 rasmus Exp $ dnl -PHP_ARG_WITH(snmp,for SNMP support,
-[ --with-snmp[=DIR] Include SNMP support.])+PHP_ARG_WITH(snmp,for SNMP support - old UCD SNNP,
+[ --with-snmp[=DIR] Include SNMP support - old UCD SNNP.])if test "$PHP_SNMP" != "no"; then @@ -61,6 +61,7 @@
AC_CHECK_LIB(kstat, kstat_read, [ PHP_ADD_LIBRARY(kstat,,SNMP_SHARED_LIBADD) ])
+ AC_DEFINE(OLD_UCD_SNMP,1,[ ])
AC_DEFINE(HAVE_SNMP,1,[ ])
PHP_ADD_INCLUDE($SNMP_INCDIR)
PHP_ADD_LIBRARY_WITH_PATH(snmp, $SNMP_LIBDIR, SNMP_SHARED_LIBADD)
@@ -82,3 +83,68 @@
],[
AC_MSG_RESULT(no)
])
+
+PHP_ARG_WITH(net-snmp,for SNMP support - NET SNNP,
+[ --with-net-snmp[=DIR] Include SNMP support - NET SNNP.])
+
+ if test "$PHP_NET_SNMP" != "no"; then
+
+ if test "$PHP_NET_SNMP" = "yes"; then + for i in /usr/include /usr/local/include; do + test -f $i/net-snmp-config.h && SNMP_INCDIR=$i + test -f $i/snmp/net-snmp-config.h && SNMP_INCDIR=$i/snmp + test -f $i/snmp/include/net-snmp/net-snmp-config.h && SNMP_INCDIR=$i/snmp/include + done + for i in /usr /usr/snmp /usr/local /usr/local/snmp; do + test -f $i/lib/libnetsnmp.a -o -f $i/lib/libnetsnmp.$SHLIB_SUFFIX_NAME && SNMP_LIBDIR=$i/lib + done + else + SNMP_INCDIR=$PHP_NET_SNMP/include + test -f $PHP_NET_SNMP/include/net-snmp/net-snmp-config.h && SNMP_INCDIR=$PHP_NET_SNMP/include + test -f $PHP_NET_SNMP/lib/libnetsnmp.a -o -f $PHP_NET_SNMP/lib/libnetsnmp.$SHLIB_SUFFIX_NAME \ + && SNMP_LIBDIR=$PHP_NET_SNMP/lib + fi+
+ if test -z "$SNMP_INCDIR"; then + AC_MSG_ERROR(net-snmp-config.h not found. Check your SNMP installation.) + elif test -z "$SNMP_LIBDIR"; then + AC_MSG_ERROR(libnetsnmp not found. Check your SNMP installation.) + fi+
+ old_CPPFLAGS=$CPPFLAGS + CPPFLAGS=-I$SNMP_INCDIR + AC_MSG_CHECKING(for OpenSSL support in SNMP libraries) + AC_EGREP_CPP(yes,[ + #include <net-snmp/net-snmp-config.h> + #if USE_OPENSSL + yes + #endif + ],[ + SNMP_SSL=yes + ],[ + SNMP_SSL=no + ]) + CPPFLAGS=$old_CPPFLAGS + AC_MSG_RESULT($SNMP_SSL)+
+ if test "$SNMP_SSL" = "yes"; then + if test "$PHP_OPENSSL" != "no"; then + PHP_ADD_LIBRARY(ssl, 1, SNMP_SHARED_LIBADD) + PHP_ADD_LIBRARY(crypto,1, SNMP_SHARED_LIBADD) + else + AC_MSG_ERROR(The NET-SNMP in this system is built with SSL support.+
+ Add --with-openssl<=DIR> to your configure line.) + fi + fi+
+ AC_CHECK_LIB(kstat, kstat_read, [ PHP_ADD_LIBRARY(kstat,,SNMP_SHARED_LIBADD) ])+
+ AC_DEFINE(HAVE_SNMP,1,[ ]) + PHP_ADD_INCLUDE($SNMP_INCDIR) + PHP_ADD_LIBRARY_WITH_PATH(netsnmp, $SNMP_LIBDIR, SNMP_SHARED_LIBADD)+
+ PHP_EXTENSION(snmp, $ext_shared) + PHP_SUBST(SNMP_SHARED_LIBADD)+ fi + Only in ext/snmp: config.m4-net-snmp Only in ext/snmp: libs.mk Only in ext/snmp: libsnmp.la diff -ru ../orig-php-4.2.2/ext/snmp/snmp.c ext/snmp/snmp.c --- ../orig-php-4.2.2/ext/snmp/snmp.c Fri Mar 1 04:31:01 2002
+++ ext/snmp/snmp.c Mon Sep 9 17:55:57 2002@@ -56,9 +56,7 @@ #endif #endif -#ifdef HAVE_DEFAULT_STORE_H -#include "default_store.h" -#endif +#ifdef OLD_UCD_SNMP #include "asn1.h" #include "snmp_api.h" #include "snmp_client.h" @@ -67,6 +65,17 @@ #include "parse.h" #include "mib.h" #include "version.h" +#else +#include "net-snmp/net-snmp-config.h" +#include "net-snmp/version.h" +#include "net-snmp/library/asn1.h" +#include "net-snmp/library/snmp_api.h" +#include "net-snmp/library/snmp_client.h" +#include "net-snmp/library/snmp_impl.h" +#include "net-snmp/library/snmp.h" +#include "net-snmp/library/parse.h" +#include "net-snmp/library/mib.h" +#endif /* ucd-snmp 3.3.1 changed the name of a few #defines... They've been changed back to the original ones in 3.5.3! */ #ifndef SNMP_MSG_GET @@ -130,7 +139,11 @@ {
php_info_print_table_start();
php_info_print_table_row(2, "UCD-SNMP Support", "enabled");
+#ifdef OLD_UCD_SNMP
php_info_print_table_row(2, "UCD-SNMP Version", VersionInfo);+#else
+ php_info_print_table_row(2, "UCD-SNMP Version", netsnmp_get_version());+#endif
php_info_print_table_end();} /* }}} */ @@ -256,7 +269,6 @@
session.timeout = timeout;
session.authenticator = NULL; - snmp_synch_setup(&session);
if ((ss = snmp_open(&session)) == NULL) {
php_error(E_WARNING,"Could not open snmp\n");
@@ -315,7 +327,11 @@
}
if (st != 11) {
+#ifdef OLD_UCD_SNMP
sprint_value((struct sbuf *)buf,vars->name, vars->name_length, vars);+#else
+ snprint_value(buf, sizeof(buf), vars->name, vars->name_length, vars);+#endif
}#if 0
Debug("snmp response is: %s\n",buf);
@@ -325,7 +341,11 @@
} else if (st == 2) {
add_next_index_string(return_value,buf,1); /* Add to returned array */
} else if (st == 3) {
+#ifdef OLD_UCD_SNMP
sprint_objid((struct sbuf *)buf2, vars->name, vars->name_length);+#else
+ snprint_objid(buf2, sizeof(buf2), vars->name, vars->name_length);+#endif add_assoc_string(return_value,buf2,buf,1);
}
if (st >= 2 && st != 11) {
@@ -344,7 +364,11 @@
for (count=1, vars = response->variables; vars && count != response->errindex;
vars = vars->next_variable, count++);
if (vars) {
+#ifdef OLD_UCD_SNMP
sprint_objid((struct sbuf *)buf,vars->name, vars->name_length);
+#else
+ snprint_objid(buf, sizeof(buf), vars->name, vars->name_length);+#endif
}
php_error(E_WARNING,"This name does not exist: %s\n",buf);
}
===========================================================================
===============================