php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65808 the socket_connect() won't work with IPv6 address
Submitted: 2013-10-02 10:11 UTC Modified: 2013-10-02 12:32 UTC
From: wzis at hotmail dot com Assigned: mike
Status: Closed Package: Sockets related
PHP Version: 5.5.4 OS: Linux
Private report: No CVE-ID:
 [2013-10-02 10:11 UTC] wzis at hotmail dot com
Description:
------------
No matter give fe80::a00:27ff:fe3d:af20 or fe80::a00:27ff:fe3d:af20%eth0 as the address, the socket_connect will just fail.
From strace and the PHP source code, what I found is the sin6_scope_id always equals to 0, while with telnet when passed in fe80::a00:27ff:fe3d:af20%eth0, from strace, we got sin6_scope_id=if_nametoindex("eth0"). So the socket_connect code needs be changed for proper IPv6 support.

Test script:
---------------
#!/usr/bin/php
<?php
  $sock=socket_create(AF_INET6, SOCK_STREAM, 0);
  if(socket_connect($sock, $argv[1], $argv[2]))
    echo "Connected to ".$argv[1]." port ".$argv[2];
?>

Expected result:
----------------
If you run the script with
  ./phpscript 2606:4100:3880:1250::100 80
You should see "Connected to 2606:4100:3880:1250::100 port 80"

Actual result:
--------------
PHP Warning:  socket_connect(): unable to connect [22]: Invalid argument in phpscript on line 4.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-02 12:32 UTC] mike@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: mike
 [2013-10-02 13:56 UTC] mike@php.net
Automatic comment on behalf of mike
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9209c19f8f7eef807cb457b32d3ab517ff8dc178
Log: fix bug #65808 	the socket_connect() won't work with IPv6 address
 [2013-10-02 13:56 UTC] mike@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 23:01:58 2014 UTC