Req->Bug #81416 [Opn->Ver]: Missing SNMP constant for Counter32 type
Edit report at https://bugs.php.net/bug.php?id=81416&edit=1
ID: 81416
Updated by: cmb@php.net
Reported by: miloslav dot hula at gmail dot com
Summary: Missing SNMP constant for Counter32 type
-Status: Open
+Status: Verified
-Type: Feature/Change Request
+Type: Bug
Package: SNMP related
Operating System: Linux
PHP Version: 8.0.10
Block user comment: N
Private report: N
New Comment:
> So SNMP_COUNTER === SNMP_UNSIGNED which I think is a mistake.
Right. That just doesn't make sense, but as you already
mentioned, we probably can't change that after 18 years due to BC
reasons.
> [â¦] or define new constant SNMP_COUNTER32 to prevent BC break.
That might the most reasonable way forward. And likely deprecate
SNMP_COUNTER right away.
Previous Comments:
------------------------------------------------------------------------
[2021-09-03 15:56:23] miloslav dot hula at gmail dot com
Description:
------------
The SNMP_VALUE_OBJECT type can be 65 for which is missing PHP SNMP constant. For example I get:
type = 65
value = 'Counter32: 231'
There is defined SNMP_COUNTER, internally defined as ASN_GAUGE, which is equal to ASN_UNSIGNED,
which is definition for SNMP_UNSIGNED.
So SNMP_COUNTER === SNMP_UNSIGNED which I think is a mistake.
https://github.com/php/php-src/blob/218fd03532ecd955dbe6e5f08b9b970f36f8b6c1/ext/snmp/snmp.c#L2052
https://github.com/net-snmp/net-snmp/blob/4ff38daccd86dd0e7c3c2385dcf2152e2e74cb88/include/net-snmp/library/snmp_impl.h#L90-L91
Soulution would be probably redefine SNMP_COUNTER as ASN_COUNTER, or define new constant
SNMP_COUNTER32 to prevent BC break.
Test script:
---------------
<?php
$types = [
'SNMP_INTEGER',
'SNMP_BIT_STR',
'SNMP_OCTET_STR',
'SNMP_NULL',
'SNMP_OBJECT_ID',
'SNMP_IPADDRESS',
'SNMP_COUNTER',
'SNMP_UNSIGNED',
'SNMP_TIMETICKS',
'SNMP_OPAQUE',
'SNMP_COUNTER64',
'SNMP_UINTEGER',
];
foreach ($types as $type) {
echo sprintf('%14s = %d', $type, constant($type)) . "\n";
}
Actual result:
--------------
SNMP_INTEGER = 2
SNMP_BIT_STR = 3
SNMP_OCTET_STR = 4
SNMP_NULL = 5
SNMP_OBJECT_ID = 6
SNMP_IPADDRESS = 64
SNMP_COUNTER = 66 <-- should be 65
SNMP_UNSIGNED = 66
SNMP_TIMETICKS = 67
SNMP_OPAQUE = 68
SNMP_COUNTER64 = 70
SNMP_UINTEGER = 71
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81416&edit=1
Thread (2 messages)