1--TEST--
2Test if socket_recvfrom() receives data sent by socket_sendto() via IPv6 UDP (Win32)
3--EXTENSIONS--
4sockets
5--SKIPIF--
6<?php
7
8if (substr(PHP_OS, 0, 3) != 'WIN') {
9    die('skip only for Windows');
10}
11require 'ipv6_skipif.inc';
12--FILE--
13<?php
14    $socket = socket_create(AF_INET6, SOCK_DGRAM, SOL_UDP);
15    if (!$socket) {
16        die('Unable to create AF_INET6 socket');
17    }
18    if (!socket_set_nonblock($socket)) {
19        die('Unable to set nonblocking mode for socket');
20    }
21    socket_recvfrom($socket, $buf, 12, 0, $from, $port); // cause warning
22    $address = '::1';
23    if (!socket_bind($socket, $address, 1223)) {
24        die("Unable to bind to $address:1223");
25    }
26
27    $msg = "Ping!";
28    $len = strlen($msg);
29    $bytes_sent = socket_sendto($socket, $msg, $len, 0, $address, 1223);
30    if ($bytes_sent == -1) {
31        die('An error occurred while sending to the socket');
32    } else if ($bytes_sent != $len) {
33        die($bytes_sent . ' bytes have been sent instead of the ' . $len . ' bytes expected');
34    }
35
36    $from = "";
37    $port = 0;
38    $bytes_received = socket_recvfrom($socket, $buf, 12, 0, $from, $port);
39    if ($bytes_received == -1) {
40        die('An error occurred while receiving from the socket');
41    } else if ($bytes_received != $len) {
42        die($bytes_received . ' bytes have been received instead of the ' . $len . ' bytes expected');
43    }
44    echo "Received $buf from remote address $from and remote port $port" . PHP_EOL;
45
46    socket_close($socket);
47?>
48--EXPECTF--
49Warning: socket_recvfrom(): unable to recvfrom [10022]: %s in %s on line %d
50Received Ping! from remote address ::1 and remote port 1223
51--CREDITS--
52Falko Menge <mail at falko-menge dot de>
53PHP Testfest Berlin 2009-05-09
54