Skip to content

Commit 9501304

Browse files
selivernikic
authored andcommitted
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.
1 parent 67352cb commit 9501304

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ PHP NEWS
1414
for FIREBIRD >= 3.0). (Dorin Marcoci)
1515
. Fixed bug #76488 (Memory leak when fetching a BLOB field). (Simonov Denis)
1616

17+
- Standard:
18+
. Fixed bug #76136 (stream_socket_get_name should enclose IPv6 in brackets).
19+
(seliver)
20+
1721
05 Jul 2018, PHP 7.3.0alpha3
1822

1923
- Core:

UPGRADING

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,10 @@ SimpleXML:
152152
Standard:
153153
. Undefined variables passed to compact() will now be reported as a notice.
154154
. getimagesize() and related functions now report the mime type of BMP images
155-
as image/bmp instead of image/x-ms-bmp, since the former has been registered
156-
with the IANA (see RFC 7903).
155+
as image/bmp instead of image/x-ms-bmp, since the former has been registered
156+
with the IANA (see RFC 7903).
157+
. stream_socket_get_name() will now return IPv6 addresses wrapped in brackets.
158+
For example "[::1]:1337" will be returned instead of "::1:1337".
157159

158160
========================================
159161
2. New Features
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug #76136: stream_socket_get_name should enclose IPv6 in brackets
3+
--SKIPIF--
4+
<?php
5+
@stream_socket_client('tcp://[::1]:0', $errno);
6+
if ($errno != 111) {
7+
die('skip IPv6 is not supported.');
8+
}
9+
?>
10+
--FILE--
11+
<?php
12+
$server = stream_socket_server("tcp://[::1]:1337/");
13+
echo stream_socket_get_name($server, false).PHP_EOL;
14+
$server = stream_socket_server("tcp://127.0.0.1:1337/");
15+
echo stream_socket_get_name($server, false);
16+
?>
17+
--EXPECT--
18+
[::1]:1337
19+
127.0.0.1:1337

main/network.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ PHPAPI void php_network_populate_name_from_sockaddr(
626626
case AF_INET6:
627627
buf = (char*)inet_ntop(sa->sa_family, &((struct sockaddr_in6*)sa)->sin6_addr, (char *)&abuf, sizeof(abuf));
628628
if (buf) {
629-
*textaddr = strpprintf(0, "%s:%d",
629+
*textaddr = strpprintf(0, "[%s]:%d",
630630
buf, ntohs(((struct sockaddr_in6*)sa)->sin6_port));
631631
}
632632

0 commit comments

Comments
 (0)