|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #42918 IPv6 addresses not supported in SNMP extension
Submitted: 2007-10-10 14:39 UTC Modified: 2011-08-25 21:41 UTC
Avg. Score:4.6 ± 0.8
Reproduced:11 of 11 (100.0%)
Same Version:3 (27.3%)
Same OS:8 (72.7%)
From: estesp at fastmail dot us Assigned: lytboris (profile)
Status: Closed Package: SNMP related
PHP Version: 5CVS-2007-10-10 (snap) OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: estesp at fastmail dot us
New email:
PHP Version: OS:


 [2007-10-10 14:39 UTC] estesp at fastmail dot us
The snmp interface code in php5 does not properly support IPv6 addresses for the hostname.  Since net-snmp 5.x the SNMP daemon can be listening on udp6 port and therefore, the hostname passed could be a valid IPv6 address.

However, the code in the snmp extension has:

     if ((pptr = strchr (hostname, ':'))) {
                remote_port = strtol (pptr + 1, NULL, 0);

So, instead of defaulting to the usual (default) snmp port, given an IPv6 address, it is taking everything past the first colon as the port number.. which, I believe is going to give a very interesting port number for most IPv6 addresses :)

Reproduce code:
Just call snmpget() with an IPv6 IP address.. you will get a host not found, or similar:

$host = '0000:0000:0000:0000:0000:0000:0000:0001';
$community = 'public';
$sysName = snmpget($host, $community, "system.sysName.0");
print "$sysName

Expected result:
snmpget() should work for IPv6 addresses given you have a net-snmp version with IPv6 support and have snmpd listening on an IPv6 transport.

Actual result:
PHP Warning:  snmpget(): Could not open snmp connection: Unknown host
(0000:0000:0000:0000:0000:0000:0000:0001) in /my_ipv6_php on line 4

There may be other issues here as "unknown host" sounds like a getaddrinfo problem, but since doing an snmpget on the server in Ipv6 mode outside of php5 works, I have to bet that something in the snmp interface in php5 is broken with respect to IPv6.


php_bug42918.diff (last revision 2011-08-21 23:35 UTC by

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-14 14:39 UTC] j dot ek at gmx dot net
Actually the code mentioned above occurs two times. First time in function "php_snmpv3" (for SNMPv3) and second in "php_snmp" (for v1 and v2c).

It also seems that some other things should be updated to support IPv6 addresses, e.g. not only support IpAddress SMIv2 Base Type but also the more generic address schema described in RFC3291. On the other hand I cannot say whether the net-snmp library already does support this, but as they claim to be fully IPv6 compatible, it's worth a try.
 [2011-04-08 21:12 UTC]
-Package: Feature/Change Request +Package: SNMP related
 [2011-07-29 01:17 UTC]
Ping! This is 2011 and IPv6 spreading!

Fixing this issue shouldn't be very hard as the underlying Net_SNMP library already supports IPv6:

  $ snmpwalk -v 2c -c public 'udp6:[::1]' sysname
  SNMPv2-MIB::sysName.0 = STRING: james
  $ snmpwalk -v 2c -c public 'udp6:::1' sysname
  SNMPv2-MIB::sysName.0 = STRING: james

For testing the following hast to be put into /etc/snmp/snmpd.conf:

   agentAddress  udp:,udp6:[::1]:161
   rwcommunity6 private ::1
   rocommunity6 public ::1

Currently PHP still gives the following error:
   $ ~/workspace/php-src-5.4/sapi/cli/php -r 'echo snmpget("::1", "private", "IF-MIB::ifAlias.1");'

   Warning: snmpget(): Could not open snmp connection: Unknown host (::1) (Illegal seek) in Command line code on line 1

Different formats like "[::1]:161" or "::1:161" make no difference.
 [2011-08-14 19:40 UTC]
-Assigned To: +Assigned To: lytboris
 [2011-08-20 15:53 UTC]
Automatic comment from SVN on behalf of lytboris
Log: Adding IPv6 support (FR #42918)
 [2011-08-20 16:10 UTC]
Automatic comment from SVN on behalf of lytboris
Log: merge from trunk two commits:
Adding IPv6 support (FR #42918)
more code coverage
 [2011-08-20 16:24 UTC]
Automatic comment from SVN on behalf of lytboris
Log: document FR #55312, #42918
 [2011-08-20 16:24 UTC]
-Status: Assigned +Status: Feedback
 [2011-08-20 16:24 UTC]
Please try using this snapshot:
For Windows:

 [2011-08-20 20:55 UTC]
Automatic comment from SVN on behalf of lytboris
Log: IPv6 Support for SNMP. (FR #42918)
 [2011-08-21 23:34 UTC]
Now it works, thanks!

Attached you find a diff that adds two basic tests for "udp6[::1]" as hostname.
 [2011-08-21 23:35 UTC]
The following patch has been added/updated:

Patch Name: php_bug42918.diff
Revision:   1313969737
 [2011-08-22 05:52 UTC]
There is IPv6 test both in trunk and PHP_5_4, revs 315236, 315237 already.
 [2011-08-25 21:41 UTC]
-Status: Feedback +Status: Closed -Operating System: Linux +Operating System: *
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 13 01:01:31 2024 UTC