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 (profile)
Status: Closed Package: Sockets related
PHP Version: 5.5.4 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: wzis at hotmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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
 [2014-10-07 23:17 UTC] stas@php.net
Automatic comment on behalf of mike
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=9209c19f8f7eef807cb457b32d3ab517ff8dc178
Log: fix bug #65808 	the socket_connect() won't work with IPv6 address
 [2014-10-07 23:28 UTC] stas@php.net
Automatic comment on behalf of mike
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=9209c19f8f7eef807cb457b32d3ab517ff8dc178
Log: fix bug #65808 	the socket_connect() won't work with IPv6 address
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 15:01:30 2024 UTC