MFH:- Fixed bug #44127 (UNIX abstract namespace socket connect does not work)

This commit is contained in:
Jani Taskinen 2008-07-16 14:08:38 +00:00
parent 644b06978a
commit d91bc9eca2
5 changed files with 60 additions and 5 deletions

View File

@ -1328,8 +1328,8 @@ PHP_FUNCTION(socket_connect)
memset(&s_un, 0, sizeof(struct sockaddr_un));
s_un.sun_family = AF_UNIX;
snprintf(s_un.sun_path, 108, "%s", addr);
retval = connect(php_sock->bsd_socket, (struct sockaddr *) &s_un, SUN_LEN(&s_un));
memcpy(&s_un.sun_path, addr, addr_len);
retval = connect(php_sock->bsd_socket, (struct sockaddr *) &s_un, (socklen_t) XtOffsetOf(struct sockaddr_un, sun_path) + addr_len);
break;
default:

View File

@ -3,7 +3,7 @@ IPv4 Loopback test
--SKIPIF--
<?php
if (!extension_loaded('sockets')) {
die('skip sockets extenion not available.');
die('skip sockets extension not available.');
}
?>
--FILE--

View File

@ -3,7 +3,7 @@ IPv6 Loopback test
--SKIPIF--
<?php
if (!extension_loaded('sockets')) {
die('skip sockets extenion not available.');
die('skip sockets extension not available.');
}
if (!defined("AF_INET6")) {
die('skip no IPv6 support');

View File

@ -0,0 +1,55 @@
--TEST--
Unix domain socket Loopback test
--SKIPIF--
<?php
if (!extension_loaded('sockets')) {
die('skip sockets extension not available.');
}
?>
--FILE--
<?php
$sock_path = sprintf("/tmp/%s.sock", uniqid());
if (file_exists($sock_path))
die('Temporary socket already exists.');
/* Setup socket server */
$server = socket_create(AF_UNIX, SOCK_STREAM, 0);
if (!$server) {
die('Unable to create AF_UNIX socket [server]');
}
if (!socket_bind($server, $sock_path)) {
die("Unable to bind to $sock_path");
}
if (!socket_listen($server, 2)) {
die('Unable to listen on socket');
}
/* Connect to it */
$client = socket_create(AF_UNIX, SOCK_STREAM, 0);
if (!$client) {
die('Unable to create AF_UNIX socket [client]');
}
if (!socket_connect($client, $sock_path)) {
die('Unable to connect to server socket');
}
/* Accept that connection */
$socket = socket_accept($server);
if (!$socket) {
die('Unable to accept connection');
}
socket_write($client, "ABCdef123\n");
$data = socket_read($socket, 10, PHP_BINARY_READ);
var_dump($data);
socket_close($client);
socket_close($socket);
socket_close($server);
@unlink($sock_path);
?>
--EXPECT--
string(10) "ABCdef123
"

View File

@ -621,7 +621,7 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_
parse_unix_address(xparam, &unix_addr TSRMLS_CC);
ret = php_network_connect_socket(sock->socket,
(const struct sockaddr *)&unix_addr, (socklen_t)sizeof(unix_addr),
(const struct sockaddr *)&unix_addr, (socklen_t) XtOffsetOf(struct sockaddr_un, sun_path) + xparam->inputs.namelen,
xparam->op == STREAM_XPORT_OP_CONNECT_ASYNC, xparam->inputs.timeout,
xparam->want_errortext ? &xparam->outputs.error_text : NULL,
&err);