|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #77661 Connection succeeds despite invalid bind address
Submitted: 2019-02-24 13:07 UTC Modified: -
From: me at tati dot pro Assigned:
Status: Open Package: Sockets related
PHP Version: master-Git-2019-02-24 (Git) OS: any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2019-02-24 13:07 UTC] me at tati dot pro
If invalid bind address is specified with stream_socket_client, than connection still be successfull.

I working with 4g usb modems, which sometimes hangs and reboots (in this time network interface is not available, so i receiving error that bind fails).

Checking if interfaces is not available before creating socket working 99% times, but not 100%.

If i receive that error than i can close socket immediately, but syn/ack/rst sequence 'll be produced that is undesirable behavior.

My program should not work if binding fails, because routing 'll be incorrect in this case.

So i need the way to change behavior, like an additional stream option that 'll force connection error if bind fails.

Test script:
$context = stream_context_create(array('socket'=>array('bindto'=>'')));

$stream = stream_socket_client('tcp://', $errno, $errstr, 10, STREAM_CLIENT_CONNECT, $context);


Expected result:
Connection should not be created.

Actual result:
PHP Warning:  stream_socket_client(): failed to bind to '', system said: Cannot assign requested address in /home/tatikoma/z.php on line 4
PHP Stack trace:
PHP   1. {main}() /home/tatikoma/z.php:0
PHP   2. stream_socket_client() /home/tatikoma/z.php:4
resource(5) of type (stream)


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 19 13:01:31 2024 UTC