Fixed bug #76136 (stream_socket_get_name enclosed IPv6 in brackets)

The IPv6 IP of a socket is provided by inet_ntop() as a string, but
this function doesn't enclose the IP in brackets. This patch adds
them in the php_network_populate_name_from_sockaddr() function.
This commit is contained in:
seliver 2018-03-31 04:05:12 +01:00 committed by Nikita Popov
parent 67352cb2c0
commit 95013042bf
4 changed files with 28 additions and 3 deletions

4
NEWS
View File

@ -14,6 +14,10 @@ PHP NEWS
for FIREBIRD >= 3.0). (Dorin Marcoci)
. Fixed bug #76488 (Memory leak when fetching a BLOB field). (Simonov Denis)
- Standard:
. Fixed bug #76136 (stream_socket_get_name should enclose IPv6 in brackets).
(seliver)
05 Jul 2018, PHP 7.3.0alpha3
- Core:

View File

@ -152,8 +152,10 @@ SimpleXML:
Standard:
. Undefined variables passed to compact() will now be reported as a notice.
. getimagesize() and related functions now report the mime type of BMP images
as image/bmp instead of image/x-ms-bmp, since the former has been registered
with the IANA (see RFC 7903).
as image/bmp instead of image/x-ms-bmp, since the former has been registered
with the IANA (see RFC 7903).
. stream_socket_get_name() will now return IPv6 addresses wrapped in brackets.
For example "[::1]:1337" will be returned instead of "::1:1337".
========================================
2. New Features

View File

@ -0,0 +1,19 @@
--TEST--
Bug #76136: stream_socket_get_name should enclose IPv6 in brackets
--SKIPIF--
<?php
@stream_socket_client('tcp://[::1]:0', $errno);
if ($errno != 111) {
die('skip IPv6 is not supported.');
}
?>
--FILE--
<?php
$server = stream_socket_server("tcp://[::1]:1337/");
echo stream_socket_get_name($server, false).PHP_EOL;
$server = stream_socket_server("tcp://127.0.0.1:1337/");
echo stream_socket_get_name($server, false);
?>
--EXPECT--
[::1]:1337
127.0.0.1:1337

View File

@ -626,7 +626,7 @@ PHPAPI void php_network_populate_name_from_sockaddr(
case AF_INET6:
buf = (char*)inet_ntop(sa->sa_family, &((struct sockaddr_in6*)sa)->sin6_addr, (char *)&abuf, sizeof(abuf));
if (buf) {
*textaddr = strpprintf(0, "%s:%d",
*textaddr = strpprintf(0, "[%s]:%d",
buf, ntohs(((struct sockaddr_in6*)sa)->sin6_port));
}