|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16664 PHP crashes on socket_bind
Submitted: 2002-04-17 13:32 UTC Modified: 2003-04-21 15:05 UTC
From: tech at kalyweb dot com Assigned:
Status: Closed Package: Sockets related
PHP Version: 4.2.0 OS: Windows 9x
Private report: No CVE-ID: None
 [2002-04-17 13:32 UTC] tech at kalyweb dot com
When I attempt to bind a socket with socket_bind, PHP crashes.
It doesn't crash if the IP to bind to is an mepty string ("") ...

I have this error in the crash dialog :
PHP a caus? une d?faillance de page dans
 le module MSVCRT.DLL ? 0167:78011f41.
Registres :
EAX=00002741 CS=0167 EIP=78011f41 EFLGS=00010206
EBX=00000073 SS=016f ESP=0063ee90 EBP=0063f0e4
ECX=00002741 DS=016f ESI=7ffffffe FS=c617
EDX=7fffffff ES=016f EDI=01447538 GS=0000
Octets ? CS : EIP :
80 38 00 74 03 40 eb f1 2b c1 e9 85 fe ff ff c7 
?tat de la pile :
00000002 01172d94 0000000c 00023c30 bff7b30e 00410000 bff7b317 00410000 00000001 00413768 0000ffff 00023c30 0041374c 0063ef0c bff7b953 00410000 

(it's in French and my windows is French ... sorry :D )


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-17 16:03 UTC]
Please provide a short, self-contained sample (see the bug's do's and don'ts).
 [2002-04-18 06:18 UTC] tech at kalyweb dot com
Here is a small example of script ...

if (($sock = socket_create (AF_INET, SOCK_STREAM, 0)) < 0) {
  echo "socket_create() failed: reason: " . socket_strerror ($sock) . "\n";
if (($ret = socket_bind ($sock, '', 10000)) < 0) {
  echo "socket_bind() failed: reason: " . socket_strerror ($ret) . "\n";

PHP crashes here, on the socket_bind command.
This script was found on the page about the socket functions. I've downloaded the last RC version but it also crashes.
I have the window's dialog with 'Close', 'Debug' or 'Deltails >>' ...
 [2002-04-18 06:20 UTC] tech at kalyweb dot com
The category has changed to PDF functions (I made a mistake while filling the form ?? ).
Changing back to 'Socket related' ...
 [2002-04-18 07:21 UTC]
Ok, I can't reproduce this on w2k (I don't have a w98 system to test).

First, try if it works on w2k for you. If it works, we know it's w98 system problem and we can dig furhter into that direction.

Second, your return checking's aren't very good. socket_create() returns either resource or false, but not something which we would say is '< 0'.

The same for socket_bind(), it returns an boolean, true or false, nothing else.

(that's from the source, the documentation on is outdated as there have been recent changes to the sources).
 [2002-04-18 07:34 UTC] tech at kalyweb dot com
This problem doesn't happens on w2k ...
It's w9x specific problem (win95 is also concerned).

PS: My test code was found in the documentation. I've updated my code ...
PS2: I'll look in the source and do some tries to find a way to fix this bug (I have VC++, I could use another compiler but I have only this one).

I know it's a bind error and if the IP is changed to "" no error happens ...
 [2002-04-18 09:17 UTC] tech at kalyweb dot com
The CSV version doesn't include this bug anymore.

Just one more thing : socket_bind() returns '' on success ...
 [2002-04-18 09:27 UTC] tech at kalyweb dot com
Oops !!
I made an error, socket_bind returns 1 on success.
True = -1
 [2002-04-18 10:59 UTC]
Wait, did you test with CVS now?!

It's supposed to ONLY return boolean false or true (from reading the source code).

Can you verify this too please.
 [2002-08-25 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2003-04-16 04:24 UTC] menace at it dot dk
win98 will crash if you bind_socket your IP to other than yourself - IP cant be either
 [2003-04-21 15:05 UTC]
This looks more like a socket_strerror() problem that was addressed recently, as the legacy winsock(1.1) doesn't report a correct errno when bind() fails according to,

WSAEADDRNOTAVAIL (10049) Cannot assign requested address. 

Berkeley description: Normally results from an attempt to create a socket with an address not on this machine. 

WinSock description: Partly the same as Berkeley. The "address" it refers to is the remote socket name (protocol, port and address). This error occurs when the sin_port value is zero in a sockaddr_in structure for connect() or sendto(). 

In Berkeley, this error also occurs when you are trying to name the local socket (assign local address and port number) with bind(), but Windows Sockets doesn't ascribe this error to bind(), for some unknown reason. 

Developer suggestions: Assume bind() will fail with this error. Let the network system assign the default local IP address by referencing INADDR_ANY in the sin_addr field of a sockaddr_in structure input to bind(). Alternately, you can get the local IP address by calling gethostname() followed by gethostbyname(). 

WinSock functions: connect(), sendto(), FD_CONNECT 

Additional functions: It seems odd that the v1.1 specification doesn't ascribe this error to the function bind().


PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Dec 01 07:05:54 2022 UTC