]> granicus.if.org Git - php/commitdiff
merge from trunk:
authorBoris Lytochkin <lytboris@php.net>
Fri, 13 Jan 2012 18:46:56 +0000 (18:46 +0000)
committerBoris Lytochkin <lytboris@php.net>
Fri, 13 Jan 2012 18:46:56 +0000 (18:46 +0000)
Fixed bug #60585 (php build fails with USE flag snmp when IPv6 support is disabled
Fixed bug #60749 (SNMP module should not strip non-standard SNMP port from hostname

NEWS
ext/snmp/snmp.c
ext/snmp/tests/bug60749.phpt [new file with mode: 0644]
ext/snmp/tests/ipv6.phpt

diff --git a/NEWS b/NEWS
index bbb6334b2cd0596e817e6c71b02b060b5321c210..804f6d3226025c7541670ce8caaa3e10e75c8ccc 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,12 @@ PHP                                                                        NEWS
   . Fixed bug #53280 (segfaults if query column count less than param count). 
     (Mariuz)
 
+- SNMP:
+  . Fixed bug #60585 (php build fails with USE flag snmp when IPv6 support
+    is disabled). (Boris Lytochkin)
+  . Fixed bug #60749 (SNMP module should not strip non-standard SNMP port
+    from hostname). (Boris Lytochkin)
+
 07 Jan 2012, PHP 5.4.0 RC5
 - Core:
   . Fixed bug #60613 (Segmentation fault with $cls->{expr}() syntax). (Dmitry)
index eb833c37d380934cf471198a7d6ccac4a3f4c65c..403c629559eea24a09a643e2b54ea75d2628b9c9 100644 (file)
@@ -1171,11 +1171,11 @@ static int netsnmp_session_init(php_snmp_session **session_p, int version, char
                        continue;
                }
 #else
-               if (res->sa_family != AF_INET) {
+               if ((*res)->sa_family != AF_INET) {
                        res++;
                        continue;
                }
-               strcat(pptr, inet_ntoa(res));
+               strcat(pptr, inet_ntoa(((struct sockaddr_in*)(*res))->sin_addr));
 #endif
                break;
        }
@@ -1188,6 +1188,12 @@ static int netsnmp_session_init(php_snmp_session **session_p, int version, char
                There should be check for non-empty session->peername!
        */
 
+       /* put back non-standard SNMP port */
+       if (session->remote_port != SNMP_PORT) {
+               pptr = session->peername + strlen(session->peername);
+               sprintf(pptr, ":%d", session->remote_port);
+       }
+
        php_network_freeaddresses(psal);
 
        if (version == SNMP_VERSION_3) {
diff --git a/ext/snmp/tests/bug60749.phpt b/ext/snmp/tests/bug60749.phpt
new file mode 100644 (file)
index 0000000..302f351
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--                                 
+Bug #60749: SNMP module should not strip non-standard SNMP port from hostname
+--CREDITS--
+Boris Lytochkin
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+require_once(dirname(__FILE__).'/snmp_include.inc');
+
+$hostname = "php.net";
+$ip = gethostbyname($hostname);
+if (ip2long($ip) === FALSE) {
+       echo "Could not resolve $hostname properly!\n";
+       exit(1);
+}
+$port = 1161;
+$session = new SNMP(SNMP::VERSION_1, "$hostname:$port", $community, $timeout, $retries);
+$info = $session->info;
+if (strcmp($info["hostname"], "$ip:$port") !== 0) {
+       echo "'" . $info["hostname"] . "' != '$ip:$port'\n";
+}
+var_dump($session->close());
+?>
+--EXPECTF--
+bool(true)
index 78119d15751906e9e9f3e6dae5ccb80ea40e837c..12879416c6284dbcd019d0a9c4df3ecd0dc926f0 100644 (file)
@@ -4,16 +4,17 @@ IPv6 support
 Boris Lytochkin
 --SKIPIF--
 <?php
-       require_once(dirname(__FILE__).'/skipif.inc');
+require_once(dirname(__FILE__).'/skipif.inc');
 
-       if (!function_exists("inet_ntop")) die("skip no inet_ntop()");
+$packed = str_repeat(chr(0), 15) . chr(1);
+if (@inet_ntop($packed) === false) {
+       die("skip no IPv6 support");
+}
 ?>
 --FILE--
 <?php
 require_once(dirname(__FILE__).'/snmp_include.inc');
 
-$default_port = 161;
-
 //EXPECTF format is quickprint OFF
 snmp_set_quick_print(false);
 snmp_set_valueretrieval(SNMP_VALUE_PLAIN);