Req #77661 [NEW]: Connection succeeds despite invalid bind address
| From: | me at tati dot pro | Date: | Sun, 24 Feb 2019 13:07:37 +0000 |
| Subject: | Req #77661 [NEW]: Connection succeeds despite invalid bind address | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-219717@lists.php.net to get a copy of this message | ||
From: me at tati dot pro
Operating system: any
PHP version: master-Git-2019-02-24 (Git)
Package: Sockets related
Bug Type: Feature/Change Request
Bug description:Connection succeeds despite invalid bind address
Description:
------------
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.
https://github.com/php/php-src/blob/623911f993f39ebbe75abe2771fc89faf6b15b9b/main/network.c#L876
Test script:
---------------
$context =
stream_context_create(array('socket'=>array('bindto'=>'1.2.3.4:5678')));
$stream = stream_socket_client('tcp://google.com:80', $errno, $errstr,
10, STREAM_CLIENT_CONNECT, $context);
var_dump($stream);
Expected result:
----------------
Connection should not be created.
Actual result:
--------------
PHP Warning: stream_socket_client(): failed to bind to '1.2.3.4:5678',
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)
--
Edit bug report at https://bugs.php.net/bug.php?id=77661&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77661&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77661&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77661&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77661&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77661&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77661&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77661&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77661&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77661&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77661&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77661&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77661&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77661&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77661&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77661&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77661&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77661&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77661&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77661&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77661&r=mysqlcfg