summaryrefslogtreecommitdiff
path: root/ext/sockets
diff options
context:
space:
mode:
Diffstat (limited to 'ext/sockets')
-rw-r--r--ext/sockets/tests/ipv4loop.phpt13
-rw-r--r--ext/sockets/tests/ipv6loop.phpt13
-rw-r--r--ext/sockets/tests/socket_getpeername_ipv4loop.phpt24
-rw-r--r--ext/sockets/tests/socket_getpeername_ipv6loop.phpt24
4 files changed, 50 insertions, 24 deletions
diff --git a/ext/sockets/tests/ipv4loop.phpt b/ext/sockets/tests/ipv4loop.phpt
index 9fdcc17dad..920b27b66e 100644
--- a/ext/sockets/tests/ipv4loop.phpt
+++ b/ext/sockets/tests/ipv4loop.phpt
@@ -13,8 +13,15 @@ IPv4 Loopback test
if (!$server) {
die('Unable to create AF_INET socket [server]');
}
- if (!socket_bind($server, '127.0.0.1', 31337)) {
- die('Unable to bind to 127.0.0.1:31337');
+ $bound = false;
+ for($port = 31337; $port < 31357; ++$port) {
+ if (socket_bind($server, '127.0.0.1', $port)) {
+ $bound = true;
+ break;
+ }
+ }
+ if (!$bound) {
+ die("Unable to bind to 127.0.0.1");
}
if (!socket_listen($server, 2)) {
die('Unable to listen on socket');
@@ -25,7 +32,7 @@ IPv4 Loopback test
if (!$client) {
die('Unable to create AF_INET socket [client]');
}
- if (!socket_connect($client, '127.0.0.1', 31337)) {
+ if (!socket_connect($client, '127.0.0.1', $port)) {
die('Unable to connect to server socket');
}
diff --git a/ext/sockets/tests/ipv6loop.phpt b/ext/sockets/tests/ipv6loop.phpt
index 6967605ffa..0d51bb090b 100644
--- a/ext/sockets/tests/ipv6loop.phpt
+++ b/ext/sockets/tests/ipv6loop.phpt
@@ -14,8 +14,15 @@ IPv6 Loopback test
if (!$server) {
die('Unable to create AF_INET6 socket [server]');
}
- if (!socket_bind($server, '::1', 31337)) {
- die('Unable to bind to [::1]:31337');
+ $bound = false;
+ for($port = 31337; $port < 31357; ++$port) {
+ if (socket_bind($server, '::1', $port)) {
+ $bound = true;
+ break;
+ }
+ }
+ if (!$bound)
+ die("Unable to bind to [::1]:$port");
}
if (!socket_listen($server, 2)) {
die('Unable to listen on socket');
@@ -26,7 +33,7 @@ IPv6 Loopback test
if (!$client) {
die('Unable to create AF_INET6 socket [client]');
}
- if (!socket_connect($client, '::1', 31337)) {
+ if (!socket_connect($client, '::1', $port)) {
die('Unable to connect to server socket');
}
diff --git a/ext/sockets/tests/socket_getpeername_ipv4loop.phpt b/ext/sockets/tests/socket_getpeername_ipv4loop.phpt
index aa59abb8da..b948e0e7f4 100644
--- a/ext/sockets/tests/socket_getpeername_ipv4loop.phpt
+++ b/ext/sockets/tests/socket_getpeername_ipv4loop.phpt
@@ -14,17 +14,23 @@ ext/sockets - socket_getpeername_ipv4loop - basic test
/* Bind and connect sockets to localhost */
$localhost = '127.0.0.1';
- /* Hold the port associated to address */
- $port = 31337;
-
/* Setup socket server */
$server = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
if (!$server) {
die('Unable to create AF_INET socket [server]');
}
-
- if (!socket_bind($server, $localhost, $port)) {
- die('Unable to bind to '.$localhost.':'.$port);
+
+ $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');
@@ -45,10 +51,10 @@ ext/sockets - socket_getpeername_ipv4loop - basic test
die('Unable to accept connection');
}
- if (!socket_getpeername($client, $address, $port)) {
+ if (!socket_getpeername($client, $address, $peerport)) {
die('Unable to retrieve peer name');
}
- var_dump($address, $port);
+ var_dump($address, $port === $peerport);
socket_close($client);
socket_close($socket);
@@ -56,4 +62,4 @@ ext/sockets - socket_getpeername_ipv4loop - basic test
?>
--EXPECT--
string(9) "127.0.0.1"
-int(31337)
+bool(true)
diff --git a/ext/sockets/tests/socket_getpeername_ipv6loop.phpt b/ext/sockets/tests/socket_getpeername_ipv6loop.phpt
index e865f3e064..5d03e32ce0 100644
--- a/ext/sockets/tests/socket_getpeername_ipv6loop.phpt
+++ b/ext/sockets/tests/socket_getpeername_ipv6loop.phpt
@@ -15,17 +15,23 @@ require 'ipv6_skipif.inc';
/* Bind and connect sockets to localhost */
$localhost = '::1';
- /* Hold the port associated to address */
- $port = 31337;
-
/* Setup socket server */
$server = socket_create(AF_INET6, SOCK_STREAM, getprotobyname('tcp'));
if (!$server) {
die('Unable to create AF_INET6 socket [server]');
}
-
- if (!socket_bind($server, $localhost, $port)) {
- die('Unable to bind to '.$localhost.':'.$port);
+
+ $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');
@@ -46,10 +52,10 @@ require 'ipv6_skipif.inc';
die('Unable to accept connection');
}
- if (!socket_getpeername($client, $address, $port)) {
+ if (!socket_getpeername($client, $address, $peerport)) {
die('Unable to retrieve peer name');
}
- var_dump($address, $port);
+ var_dump($address, $port === $peerport);
socket_close($client);
socket_close($socket);
@@ -57,4 +63,4 @@ require 'ipv6_skipif.inc';
?>
--EXPECT--
string(3) "::1"
-int(31337)
+bool(true)