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