Skip to content

Commit 23706f1

Browse files
author
foobar
committed
Make this thing to compile with net-snmp-5.0.x
1 parent 226f0a1 commit 23706f1

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

ext/snmp/config.m4

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,34 @@ dnl
55
PHP_ARG_WITH(snmp,for SNMP support,
66
[ --with-snmp[=DIR] Include SNMP support.])
77

8-
if test "$PHP_SNMP" != "no"; then
8+
if test "$PHP_SNMP" != "no"; then
9+
10+
dnl
11+
dnl Try net-snmp first
12+
dnl
13+
if test "$PHP_SNMP" = "yes"; then
14+
AC_PATH_PROG(SNMP_CONFIG,net-snmp-config,,[/usr/local/bin:$PATH])
15+
else
16+
SNMP_CONFIG="$PHP_SNMP/bin/net-snmp-config"
17+
fi
18+
19+
if test -x "$SNMP_CONFIG"; then
20+
SNMP_LIBS=`$SNMP_CONFIG --netsnmp-libs`
21+
SNMP_LIBS="$SNMP_LIBS `$SNMP_CONFIG --external-libs`"
22+
SNMP_PREFIX=`$SNMP_CONFIG --prefix`
23+
24+
if test -n "$SNMP_LIBS" && test -n "$SNMP_PREFIX"; then
25+
PHP_ADD_INCLUDE(${SNMP_PREFIX}/include)
26+
PHP_EVAL_LIBLINE($SNMP_LIBS, SNMP_SHARED_LIBADD)
27+
AC_DEFINE(HAVE_NET_SNMP,1,[ ])
28+
else
29+
AC_MSG_ERROR([Could not find the required paths. Please check your net-snmp installation.])
30+
fi
31+
else
32+
33+
dnl
34+
dnl Try ucd-snmp if net-snmp test failed
35+
dnl
936

1037
if test "$PHP_SNMP" = "yes"; then
1138
for i in /usr/include /usr/local/include; do
@@ -60,15 +87,15 @@ PHP_ARG_WITH(snmp,for SNMP support,
6087
fi
6188

6289
AC_CHECK_LIB(kstat, kstat_read, [ PHP_ADD_LIBRARY(kstat,,SNMP_SHARED_LIBADD) ])
63-
64-
AC_DEFINE(HAVE_SNMP,1,[ ])
6590
PHP_ADD_INCLUDE($SNMP_INCDIR)
6691
PHP_ADD_LIBRARY_WITH_PATH(snmp, $SNMP_LIBDIR, SNMP_SHARED_LIBADD)
67-
68-
PHP_NEW_EXTENSION(snmp, snmp.c, $ext_shared)
69-
PHP_SUBST(SNMP_SHARED_LIBADD)
7092
fi
7193

94+
PHP_NEW_EXTENSION(snmp, snmp.c, $ext_shared)
95+
PHP_SUBST(SNMP_SHARED_LIBADD)
96+
AC_DEFINE(HAVE_SNMP,1,[ ])
97+
fi
98+
7299

73100
AC_MSG_CHECKING(whether to enable UCD SNMP hack)
74101
AC_ARG_ENABLE(ucd-snmp-hack,

ext/snmp/snmp.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
#include "php.h"
2727
#include "ext/standard/info.h"
2828
#include "php_snmp.h"
29+
30+
#if HAVE_SNMP
31+
2932
#include <sys/types.h>
3033
#ifdef PHP_WIN32
3134
#include <winsock.h>
@@ -60,7 +63,6 @@
6063
#ifdef HAVE_UNISTD_H
6164
#include <unistd.h>
6265
#endif
63-
#if HAVE_SNMP
6466

6567
#ifndef __P
6668
#ifdef __GNUC__
@@ -70,6 +72,11 @@
7072
#endif
7173
#endif
7274

75+
#ifdef HAVE_NET_SNMP
76+
#include <net-snmp/net-snmp-config.h>
77+
#include <net-snmp/net-snmp-includes.h>
78+
#define VersionInfo NetSnmpVersionInfo
79+
#else
7380
#ifdef HAVE_DEFAULT_STORE_H
7481
#include "default_store.h"
7582
#endif
@@ -81,6 +88,7 @@
8188
#include "parse.h"
8289
#include "mib.h"
8390
#include "version.h"
91+
#endif
8492

8593
/* 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! */
8694
#ifndef SNMP_MSG_GET
@@ -329,15 +337,23 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st)
329337
}
330338

331339
if (st != 11) {
332-
sprint_value((struct sbuf *)buf,vars->name, vars->name_length, vars);
340+
#ifdef HAVE_NET_SNMP
341+
snprint_value(buf, strlen(buf), vars->name, vars->name_length, vars);
342+
#else
343+
sprint_value((struct sbuf *) buf,vars->name, vars->name_length, vars);
344+
#endif
333345
}
334346

335347
if (st == 1) {
336348
RETVAL_STRING(buf,1);
337349
} else if (st == 2) {
338350
add_next_index_string(return_value,buf,1); /* Add to returned array */
339351
} else if (st == 3) {
352+
#ifdef HAVE_NET_SNMP
353+
snprint_objid(buf2, strlen(buf2), vars->name, vars->name_length);
354+
#else
340355
sprint_objid((struct sbuf *)buf2, vars->name, vars->name_length);
356+
#endif
341357
add_assoc_string(return_value,buf2,buf,1);
342358
}
343359
if (st >= 2 && st != 11) {
@@ -356,7 +372,11 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st)
356372
for (count=1, vars = response->variables; vars && count != response->errindex;
357373
vars = vars->next_variable, count++);
358374
if (vars) {
375+
#ifdef HAVE_NET_SNMP
376+
snprint_objid(buf, strlen(buf), vars->name, vars->name_length);
377+
#else
359378
sprint_objid((struct sbuf *)buf,vars->name, vars->name_length);
379+
#endif
360380
}
361381
php_error(E_WARNING,"This name does not exist: %s\n",buf);
362382
}

0 commit comments

Comments
 (0)