From: info at directwebsolutions dot nl
Operating system: CentOS
PHP version: 5.6.30
Package: Streams related
Bug Type: Bug
Bug description:Bindto IPv6 works with file_get_contents but fails with stream_socket_client
Description:
------------
PHP 5.6.30 (cli) (built: Jun 2 2017 12:27:19). I experienced the same
problem with PHP 7.1.
I think it is a bug which is in PHP for quite a long time if this is the
same as bug ( https://bugs.php.net/bug.php?id=50415 ) which was
not
solved in the past.
What I try to do is:
- create streaming socket using SSL
- binding to a local IP which is not the default IP of the ethernet card
(NIC) but an additional configured address and is IPv6 (important!).
I runned quite a few tests with different parameters. I copied the code
to a single file and executed it as root in SSH to make sure it is not a
problem with privileges within the user account.
I can connect with the desired IPv6 binding to any website using
stream_context_create() on a file_get_contents() execution. I tried this
to several websites which have functionality on their website to show my
visitor IP address and then my correct IPv6 address is displayed, and
thus used.
But when I try to connect with the same IPv6 binding and exactly the
same stream_context_create() but change the function using the $context
to be stream_socket_client() then all requests fail and falls back to
the servers default IPv4 or IPv6 address.
Test script:
---------------
Script 1 (ipv6 binding with file_get_contents):
-----------------------------------------------
$context = stream_context_create(
array('socket' => array('bindto' =>
"[octect1:octect2:octect3:octect4:0000:0000:0000:0020]:0", "ipv6_v6only"
=> "ipv6_v6only"))
);
print file_get_contents('http://ipadres.bit.nl/', false, $context);
Script 2 (ipv6 binding with stream_socket_client):
-----------------------------------------------
$context = stream_context_create(
array('socket' => array('bindto' =>
"[octect1:octect2:octect3:octect4:0000:0000:0000:0020]:0", "ipv6_v6only"
=> "ipv6_v6only"))
);
$socket = stream_socket_client('ssl://'.$epp_host.':'.$epp_port.'',
$errno, $errstr, 5, STREAM_CLIENT_CONNECT, $context);
print $errno."<br>";
print $errstr."<br>";
var_dump($socket);
Expected result:
----------------
Script 1:
---------
A lot of HTML with my outgoing IPv6 address
(octect1:octect2:octect3:octect4:0000:0000:0000:0020) inside the HTML
page code.
Script 2:
---------
0
*empty $errstr*
resource(29) of type (stream)
Actual result:
--------------
Script 1:
---------
My correct outgoing non default IPv6 address is bound and thus is inside
the HTML page code.
Script 2:
---------
111
Warning: stream_socket_client(): Invalid IP Address:
octect1:octect2:octect3:octect4:0000:0000:0000:0020
bool(false)
And because the IP address is invalid i also cannot connect to the
desired servers because my IP does not pass through their firewall, so i
get a connection refused.
At the end of this bug report i found another streaming host which i
could connect to which does not have a firewall in place, and then the
correct IPv6 address CAN be bound with using the stream_socket_client()
function. So that would mean that the error "Invalid IP Address" is just
a wrong error for the situation when no connection is possible?
What is happening here? Please look into this.
--
Edit bug report at https://bugs.php.net/bug.php?id=74764&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74764&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74764&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74764&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=74764&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=74764&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=74764&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=74764&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=74764&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=74764&r=support
Expected behavior: https://bugs.php.net/fix.php?id=74764&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=74764&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=74764&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=74764&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74764&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=74764&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=74764&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=74764&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74764&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=74764&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=74764&r=mysqlcfg