php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48131 stream_context_create / bindto not working with IPv4 on a dual IPv4/IPv6 system
Submitted: 2009-05-02 13:30 UTC Modified: 2009-05-04 14:46 UTC
From: dvasseur at diway dot net Assigned: iliaa (profile)
Status: Closed Package: Streams related
PHP Version: 5.*, 6CVS (2009-05-02) OS: Linux - Ubuntu 8.10
Private report: No CVE-ID: None
 [2009-05-02 13:30 UTC] dvasseur at diway dot net
Description:
------------
My system has 2 ip addresses, one ipv4 (A.B.C.D) and the other ipv6 (1:2:3:4:5:6)

I'm trying to open a file over HTTP (http://other.server/my.file.dat), 'other.server' is resolving both on ipv4 and ipv6 too.

I'd like to choose wether IPv4 or IPv6 to open the file so I'm using stream_context_create() with the 'bindto' option.

'bindto' with an ipv4 address is NOT working
'bindto' with an ipv6 address is working


Reproduce code:
---------------
The following code is working (ipv6 is used)
--
$opts = array(
  'socket' => array(
      'bindto' => '[1:2:3:4:5:6]:0',
  ),
);

$context = stream_context_create($opts);

$contents = file_get_contents('http://other.server/my.file.dat', FALSE, $context);
--

The following code is NOT working:
--
$opts = array(
  'socket' => array(
      'bindto' => 'A.B.C.D:0',
  ),
);

$context = stream_context_create($opts);

$contents = file_get_contents('http://other.server/my.file.dat', FALSE, $context);
--

=> PHP Warning:  file_get_contents(): Invalid IP Address: A.B.C.D 

Expected result:
----------------
ipv4 working

Actual result:
--------------
ipv4 NOT working

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-02 19:30 UTC] dvasseur at diway dot net
Same bug with CVS snapshot
--
PHP 5.2.10-dev (cli) (built: May  2 2009 21:22:25) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
--
 [2009-05-04 14:46 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 09:01:32 2024 UTC