php-src/ext/sockets/tests/socket_getpeername_ipv4loop.phpt
Peter Kokot 128cd0d0f2 Remove old SVN keywords substitutions from xsl and sockets tests
When the PHP source code was versioned in Subversion, there was
possible to substitute certain keywords such as $Id$ with revision
number, last change time and author name. Such approach is not used
in Git so this patch removes these outdated artifacts from the xsl
and sockets extensions tests files.
2018-06-13 15:56:06 +02:00

65 lines
1.7 KiB
PHP

--TEST--
ext/sockets - socket_getpeername_ipv4loop - basic test
--CREDITS--
Tatjana Andersen tatjana.andersen@redpill-linpro.com
# TestFest 2009 - NorwayUG
--SKIPIF--
<?php
if (!extension_loaded('sockets')) {
die('skip sockets extension not available.');
}
?>
--FILE--
<?php
/* Bind and connect sockets to localhost */
$localhost = '127.0.0.1';
/* Setup socket server */
$server = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
if (!$server) {
die('Unable to create AF_INET socket [server]');
}
$minport = 31337;
$maxport = 31356;
$bound = false;
for($port = $minport; $port <= $maxport; ++$port) {
if (socket_bind($server, $localhost, $port)) {
$bound = true;
break;
}
}
if (!$bound) {
die('Unable to bind to '.$localhost);
}
if (!socket_listen($server, 2)) {
die('Unable to listen on socket');
}
/* Connect to it */
$client = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
if (!$client) {
die('Unable to create AF_INET socket [client]');
}
if (!socket_connect($client, $localhost, $port)) {
die('Unable to connect to server socket');
}
/* Accept that connection */
$socket = socket_accept($server);
if (!$socket) {
die('Unable to accept connection');
}
if (!socket_getpeername($client, $address, $peerport)) {
die('Unable to retrieve peer name');
}
var_dump($address, $port === $peerport);
socket_close($client);
socket_close($socket);
socket_close($server);
?>
--EXPECT--
string(9) "127.0.0.1"
bool(true)