1--TEST--
2Streams Based IPv6 UDP Loopback test
3--SKIPIF--
4<?php
5    /* If IPv6 is supported on the platform this will error out with code 111 -
6     * Connection refused (or code 10049 on Windows).  If IPv6 is NOT supported, $errno will be set to
7     * something else (indicating parse/getaddrinfo error)
8     * Note: Might be a good idea to export an IPv6 support indicator
9     * (such as AF_INET6 exported by ext/sockets), however, since we
10     * cannot tell for sure if IPv6 works until we probe it at run time,
11     * this isn't really practical.
12     */
13
14    @stream_socket_client('tcp://[::1]:0', $errno);
15    if ((PHP_OS_FAMILY === 'Windows' && $errno !== 10049) || (PHP_OS_FAMILY !== 'Windows' && $errno !== 111)) {
16        die('skip IPv6 is not supported.');
17    }
18?>
19--FILE--
20<?php
21
22  for ($i=0; $i<100; $i++) {
23    $port = rand(10000, 65000);
24    /* Setup socket server */
25    $server = @stream_socket_server("udp://[::1]:$port", $errno, $errstr, STREAM_SERVER_BIND);
26    if ($server) {
27      break;
28    }
29  }
30
31    if (!$server) {
32        die('Unable to create AF_INET6 socket [server]');
33    }
34
35    /* Connect to it */
36    $client = stream_socket_client("udp://[::1]:$port");
37    if (!$client) {
38        die('Unable to create AF_INET6 socket [client]');
39    }
40
41    fwrite($client, "ABCdef123\n");
42
43    $data = fread($server, 10);
44    var_dump($data);
45
46    fclose($client);
47    fclose($server);
48?>
49--EXPECT--
50string(10) "ABCdef123
51"
52