diff --git a/drivers/snmp-ups.c b/drivers/snmp-ups.c index 1d384548ff..dccf5e2e65 100644 --- a/drivers/snmp-ups.c +++ b/drivers/snmp-ups.c @@ -66,10 +66,27 @@ #include "hpe-pdu-mib.h" /* Address API change */ -#ifndef usmAESPrivProtocol +#if ( ! NUT_HAVE_LIBNETSNMP_usmAESPrivProtocol ) && ( ! defined usmAESPrivProtocol ) #define usmAESPrivProtocol usmAES128PrivProtocol #endif +#ifdef USM_PRIV_PROTO_AES_LEN +# define NUT_securityPrivProtoLen USM_PRIV_PROTO_AES_LEN +#else +# ifdef USM_PRIV_PROTO_AES128_LEN +# define NUT_securityPrivProtoLen USM_PRIV_PROTO_AES128_LEN +# else +/* FIXME: Find another way to get the size of array(?) to avoid: + * error: division 'sizeof (oid * {aka long unsigned int *}) / sizeof (oid {aka long unsigned int})' does not compute the number of array elements [-Werror=sizeof-pointer-div] + * See also https://bugs.php.net/bug.php?id=37564 for context + * which is due to most values in /usr/include/net-snmp/librarytransform_oids.h + * being defined as "oid[10]" or similar arrays, and "backwards compatibility" + * usmAESPrivProtocol name is an "oid *" pointer. + */ +# define NUT_securityPrivProtoLen (sizeof(usmAESPrivProtocol)/sizeof(oid)) +# endif +#endif + static mib2nut_info_t *mib2nut[] = { &apc, &mge, @@ -593,7 +610,7 @@ void nut_snmp_init(const char *type, const char *hostname) } else if (strcmp(privProtocol, "AES") == 0) { g_snmp_sess.securityPrivProto = usmAESPrivProtocol; - g_snmp_sess.securityPrivProtoLen = sizeof(usmAESPrivProtocol)/sizeof(oid); + g_snmp_sess.securityPrivProtoLen = NUT_securityPrivProtoLen; } else fatalx(EXIT_FAILURE, "Bad SNMPv3 authProtocol: %s", authProtocol); diff --git a/m4/nut_check_libnetsnmp.m4 b/m4/nut_check_libnetsnmp.m4 index 83b26330b7..06be25f3d3 100644 --- a/m4/nut_check_libnetsnmp.m4 +++ b/m4/nut_check_libnetsnmp.m4 @@ -75,6 +75,22 @@ if test -z "${nut_have_libnetsnmp_seen}"; then if test "${nut_have_libnetsnmp}" = "yes"; then LIBNETSNMP_CFLAGS="${CFLAGS}" LIBNETSNMP_LIBS="${LIBS}" + + AC_MSG_CHECKING([for defined usmAESPrivProtocol]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ +#include +#include +oid * pProto = usmAESPrivProtocol; +], +[] + )], + [AC_MSG_RESULT([yes]) + AC_DEFINE_UNQUOTED(NUT_HAVE_LIBNETSNMP_usmAESPrivProtocol, 1, [Variable or macro by this name is resolvable]) + ], + [AC_MSG_RESULT([no]) + AC_DEFINE_UNQUOTED(NUT_HAVE_LIBNETSNMP_usmAESPrivProtocol, 0, [Variable or macro by this name is not resolvable]) + ]) + fi dnl restore original CFLAGS and LIBS