php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #50047 interface binding for fsockopen (like socket_bind)
Submitted: 2009-11-01 00:26 UTC Modified: 2011-12-22 11:37 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: naox at o2 dot pl Assigned:
Status: Wont fix Package: Network related
PHP Version: 5.2.11 OS: -
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: naox at o2 dot pl
New email:
PHP Version: OS:

 

 [2009-11-01 00:26 UTC] naox at o2 dot pl
Description:
------------
PHP really needs interface binding for fsockopen() (like socket_bind())


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-03 03:06 UTC] srinatar@php.net
is this some thing what you are looking for ?
$fp = fsockopen("tcp://127.0.0.1", 8080);

or 
$fp = fsockopen("unix:///tmp/mysocket", ..);

 [2009-11-03 04:40 UTC] naox at o2 dot pl
nope. this would be setting destination not source interface. Check out 
http://php.net/manual/pl/function.socket-bind.php
this however is for socket functions not "network" like fsockopen
 [2010-12-20 13:18 UTC] jani@php.net
-Package: Feature/Change Request +Package: Network related
 [2011-12-21 17:32 UTC] drclue at drclue dot net
I know this is an OLD thread to be bumping , but the missing bind facility in 
fsockopen() is exactly my problem today.

The knee jerk thought that most people have is that one is trying to
bind as a server, BUT in this use case I'm binding the client.

The particular application is an ip hygiene tester for a level 3 networking
company that verifies if particular source IP addresses can send mail, prior 
to leasing them out to corporate clients like Walmart. We do various DNS lookups
to spamhaus servers , and as a final test send test mails to test email accounts
we have established at the target servers of interest to the clients to verify
the /24 ip ranges will indeed deliver mail. (THIS IS NOT A SPAM SYSTEM).  

The server I'm developing on is configured with multiple ip addresses and the 
application needs to bind the client socket to perform the tests.

My existing mail routines use fsocket functions , so I'm having to investigate
various work arounds such as making a stream wrapper just to get that bind 
function in there. I really don't want to recreate all the feof , fread , fgets 
etc. logic.
 [2011-12-22 11:37 UTC] cataphract@php.net
-Status: Open +Status: Wont fix
 [2011-12-22 11:37 UTC] cataphract@php.net
stream_socket_client already exists for this purpose:

<?php
function test($a) {
        $s = stream_socket_client(
                "tcp://nebm.geleia.net:80",
                $errno, $errstr, 1,
                STREAM_CLIENT_CONNECT,
                stream_context_create(array(
                        'socket' => array('bindto' => "[$a]:1224")
                ))
        );
        fwrite($s, "GET /whoami HTTP/1.0\r\n\r\n");
        while ($f = fgets($s)) { $line = $f; }
        echo $line, "\n";
}
test('2001:470:1f08:d77::2');
test('2001:470:94a2:1::1');
2001:470:1f08:d77::2
2001:470:94a2:1::1


One could also more simply have used file_get_contents with the http wrapper in this situation.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 23:01:26 2024 UTC