Fixed bug #60749 (SNMP module should not strip non-standard SNMP port from hostname)
Fixed ipv6 test skipto if IPv6 support is disabled
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;
}
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) {
--- /dev/null
+--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)
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);