php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16819 FormatMessage and WSAGetLastError
Submitted: 2002-04-25 06:13 UTC Modified: 2002-07-01 16:51 UTC
From: Nofin at Mail2K dot ru Assigned:
Status: Not a bug Package: Sockets related
PHP Version: 4.1.2 OS: Windows' 9x
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
35 - 4 = ?
Subscribe to this entry?

 
 [2002-04-25 06:13 UTC] Nofin at Mail2K dot ru
1) in your documentation (http://www.php.net/manual/en/function.socket-connect.php)

"socket_connect" function described as:


int socket_connect ( resource socket, string address [, int port])


but in your binaries (extensions/php_sockets.dll) and in
source codes (/ext/sockets/socket.c) this function returns 0(false) or 1(true):

...
if (retval != 0)
{
  PHP_SOCKET_ERROR(php_sock, "unable to connect", errno);
  RETURN_FALSE;
}
RETURN_TRUE;
...


Also "Example 2. Socket example: Simple TCP/IP client" (http://www.php.net/manual/en/ref.sockets.php) is wrong:

...
$socket = socket_create (AF_INET, SOCK_STREAM, 0);
if ($socket < 0) {
    echo "socket_create() failed: reason: " . socket_strerror ($socket) . "\n";
} else {
    echo "OK.\n";
}
...


Must be something like this:

>>
...
if ($socket == 0) {
...




2) Function "socket_connect" (/ext/sockets/socket.c) calls function php_error:


....
php_error(E_WARNING, "%s() %s [%d]: %s", get_active_function_name(TSRMLS_C), msg, errn, php_strerror(errn));
...


but last parameter is not a pointer to string, it's an integer number (equals to "errn"), because "php_strerror(errn)" can not return error message (function "FormatMessage" fails).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-25 06:15 UTC] mfischer@php.net
Yes, known thx. It's a documentation issue.
 [2002-04-25 06:16 UTC] Nofin at Mail2K dot ru
1) in your documentation (http://www.php.net/manual/en/function.socket-connect.php)

"socket_connect" function described as:


int socket_connect ( resource socket, string address [, int port])


but in your binaries (extensions/php_sockets.dll) and in
source codes (/ext/sockets/socket.c) this function returns 0(false) or 1(true):

...
if (retval != 0)
{
  PHP_SOCKET_ERROR(php_sock, "unable to connect", errno);
  RETURN_FALSE;
}
RETURN_TRUE;
...


Also "Example 2. Socket example: Simple TCP/IP client" (http://www.php.net/manual/en/ref.sockets.php) is wrong:

...
$socket = socket_create (AF_INET, SOCK_STREAM, 0);
if ($socket < 0) {
    echo "socket_create() failed: reason: " . socket_strerror ($socket) . "\n";
} else {
    echo "OK.\n";
}
...


Must be something like this:


...
if ($socket == 0) {
...




2) Function "socket_connect" (/ext/sockets/socket.c) calls function php_error:


....
php_error(E_WARNING, "%s() %s [%d]: %s", get_active_function_name(TSRMLS_C), msg, errn, php_strerror(errn));
...


but last parameter is not a pointer to string, it's an integer number (equals to "errn"), because "php_strerror(errn)" can not return error message (function "FormatMessage" fails).
 [2002-04-25 06:20 UTC] Nofin at Mail2K dot ru
2) Function "socket_connect" (/ext/sockets/socket.c) calls function php_error:


....
php_error(E_WARNING, "%s() %s [%d]: %s", get_active_function_name(TSRMLS_C), msg, errn, php_strerror(errn));
...


but last parameter is not a pointer to string, it's an integer number (equals to "errn"), because "php_strerror(errn)" can not return error message (function "FormatMessage" fails).
 [2002-04-25 18:34 UTC] alindeman@php.net
I fixed the return value part of the bug

 [2002-04-26 01:31 UTC] Nofin at Mail2K dot ru
For the best understanding of a problem I bring endurance from the "Winsock Programmer's FAQ":

>> Note that some people will tell you that the Win32 FormatMessage() API can be coerced into returning error messages for Winsock error numbers. At best, this is undocumented behavior that only works with some implementations of Winsock. I personally have not been able to get it to work, despite significant time devoted to the problem. My advice is that you're much better off spending your time constructing meaningful error messages than chasing something that could never work very well even if it was documented behavior. <<

Also in this book there is an example how to receive the textual message on an error from a code of an error.
If you want I can to you it(him) send.

I think that it is necessary to produce some modifications in functions ("socket.c": "php_strerror", "socket_strerror") , in connection with described above.
 [2002-07-01 16:51 UTC] jason@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately your version of PHP is too old -- the problem
might already be fixed. Please download a new PHP
version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.

Could you try a later version, the sockets extension has changed significantly since 4.1.X, and reopen if it is a problem?

Thanks,
Jason

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 01:01:28 2024 UTC