1--TEST--
2sendmsg()/recvmsg(): test ability to receive multiple messages (WIN32)
3--SKIPIF--
4<?php
5if (!extension_loaded('sockets'))
6	die('skip sockets extension not available.');
7if (!defined('IPPROTO_IPV6'))
8	die('skip IPv6 not available.');
9if (substr(PHP_OS, 0, 3) != 'WIN')
10	die('skip Only for Windows!');
11/* Windows supports IPV6_RECVTCLASS and is able to receive the tclass via
12 * WSARecvMsg (though only the top 6 bits seem to reported), but WSASendMsg
13 * does not accept IPV6_TCLASS messages. We still  test that sendmsg() works
14 * corectly by sending an IPV6_PKTINFO message that will have no effect */
15--FILE--
16<?php
17include __DIR__."/mcast_helpers.php.inc";
18$addr = '::1';
19
20echo "creating send socket\n";
21$sends1 = socket_create(AF_INET6, SOCK_DGRAM, SOL_UDP) or die("err");
22var_dump($sends1);
23$br = socket_bind($sends1, '::', 7001) or die("err");
24var_dump($br);
25socket_set_nonblock($sends1) or die("Could not put in non-blocking mode");
26
27echo "creating receive socket\n";
28$s = socket_create(AF_INET6, SOCK_DGRAM, SOL_UDP) or die("err");
29var_dump($s);
30$br = socket_bind($s, '::0', 3000) or die("err");
31var_dump($br);
32
33socket_set_option($s, IPPROTO_IPV6, IPV6_RECVPKTINFO, 1) or die("err");
34socket_set_option($s, IPPROTO_IPV6, IPV6_RECVTCLASS, 1) or die("err");
35
36$r = socket_sendmsg($sends1, [
37	"name" => [ "addr" => "::1", "port" => 3000],
38	"iov" => ["test ", "thing", "\n"],
39	"control" => [[
40		"level" => IPPROTO_IPV6,
41		"type" => IPV6_PKTINFO,
42		"data" => [
43			'addr' => '::1',
44            'ifindex' => 1 /* we're assuming loopback is 1. Is this a safe assumption? */
45		],
46	]]
47], 0);
48var_dump($r);
49checktimeout($s, 500);
50
51$data = [
52    "name" => ["family" => AF_INET6, "addr" => "::1"],
53    "buffer_size" => 2000,
54    "controllen" => socket_cmsg_space(IPPROTO_IPV6, IPV6_PKTINFO) +
55			socket_cmsg_space(IPPROTO_IPV6, IPV6_TCLASS),
56];
57if (!socket_recvmsg($s, $data, 0)) die("recvmsg");
58print_r($data);
59--EXPECTF--
60creating send socket
61resource(%d) of type (Socket)
62bool(true)
63creating receive socket
64resource(%d) of type (Socket)
65bool(true)
66int(11)
67Array
68(
69    [name] => Array
70        (
71            [family] => %d
72            [addr] => ::1
73            [port] => 7001
74            [flowinfo] => 0
75            [scope_id] => 0
76        )
77
78    [control] => Array
79        (
80            [0] => Array
81                (
82                    [level] => %d
83                    [type] => %d
84                    [data] => Array
85                        (
86                            [addr] => ::1
87                            [ifindex] => %d
88                        )
89
90                )
91
92            [1] => Array
93                (
94                    [level] => %d
95                    [type] => %d
96                    [data] => 0
97                )
98
99        )
100
101    [iov] => Array
102        (
103            [0] => test thing
104
105        )
106
107    [flags] => 0
108)
109