note 47441 added to ref.snmp
| From: | piegtas at hotmail dot com | Date: | Tue, 16 Nov 2004 15:00:28 +0000 |
| Subject: | note 47441 added to ref.snmp | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-80598@lists.php.net to get a copy of this message | ||
I'd make this patch to add SNMP v2c support. It' was tested on php-5.0.1 snmp extension
and works fine.
This patch adds an extra optional argument for all snmp functions. It could be 1 (snmp v1) or 2
(snmp v2).
Example:
snmpwalk($hostname, $community, "ifHCInOctets.1", $timeout, $retries, 2);
Regards
/-----------------------------------------/
diff -ruN ext/snmp.orig/snmp.c ext/snmp/snmp.c
--- ext/snmp.orig/snmp.c Tue Mar 23 20:12:50 2004
+++ ext/snmp/snmp.c Fri Aug 6 13:01:54 2004
@@ -530,7 +530,7 @@
*/
static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st)
{
- zval **a1, **a2, **a3, **a4, **a5, **a6, **a7;
+ zval **a1, **a2, **a3, **a4, **a5, **a6, **a7, **a8;
struct snmp_session session;
long timeout=SNMP_DEFAULT_TIMEOUT;
long retries=SNMP_DEFAULT_RETRIES;
@@ -539,10 +539,11 @@
char *value = (char *) 0;
char hostname[MAX_NAME_LEN];
int remote_port = 161;
+ int s_version = SNMP_VERSION_1;
char *pptr;
if (myargc < 3 || myargc > 7 ||
- zend_get_parameters_ex(myargc, &a1, &a2, &a3, &a4, &a5, &a6,
&a7) == FAILURE) {
+ zend_get_parameters_ex(myargc, &a1, &a2, &a3, &a4, &a5, &a6,
&a7, &a8) == FAILURE) {
WRONG_PARAM_COUNT;
}
@@ -580,6 +581,11 @@
convert_to_long_ex(a5);
retries = Z_LVAL_PP(a5);
}
+
+ if(myargc > 5) {
+ convert_to_long_ex(a6);
+ if(Z_LVAL_PP(a6) == 2) { s_version = SNMP_VERSION_2c; };
+ }
}
snmp_sess_init(&session);
@@ -590,7 +596,7 @@
session.peername = hostname;
session.remote_port = remote_port;
- session.version = SNMP_VERSION_1;
+ session.version = s_version;
/*
* FIXME: potential memory leak
* This is a workaround for an "artifact" (Mike Slifcak)
----
Manual Page -- http://www.php.net/manual/en/ref.snmp.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47441
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47441&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47441&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47441&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47441&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47441&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47441&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47441&report=yes
Search -- http://master.php.net/manage/user-notes.php