php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81416 Missing SNMP constant for Counter32 type
Submitted: 2021-09-03 15:56 UTC Modified: 2021-09-03 17:25 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: miloslav dot hula at gmail dot com Assigned:
Status: Verified Package: SNMP related
PHP Version: 8.0.10 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: miloslav dot hula at gmail dot com
New email:
PHP Version: OS:

 

 [2021-09-03 15:56 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-03 17:25 UTC] cmb@php.net
-Status: Open +Status: Verified -Type: Feature/Change Request +Type: Bug
 [2021-09-03 17:25 UTC] cmb@php.net
> 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.
 [2024-05-06 08:30 UTC] diana658hill at gmail dot com
This php bug information is very very helpful for me, Thanks for sharing this bug info (https://github.com)(https://www-floridablue.com)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC