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
16--FILE--
17<?php
18include __DIR__."/mcast_helpers.php.inc";
19$addr = '::1';
20
21echo "creating send socket\n";
22$sends1 = socket_create(AF_INET6, SOCK_DGRAM, SOL_UDP) or die("err");
23var_dump($sends1);
24$br = socket_bind($sends1, '::', 7001) or die("err");
25var_dump($br);
26socket_set_nonblock($sends1) or die("Could not put in non-blocking mode");
27
28echo "creating receive socket\n";
29$s = socket_create(AF_INET6, SOCK_DGRAM, SOL_UDP) or die("err");
30var_dump($s);
31$br = socket_bind($s, '::0', 3000) or die("err");
32var_dump($br);
33
34socket_set_option($s, IPPROTO_IPV6, IPV6_RECVPKTINFO, 1) or die("err");
35socket_set_option($s, IPPROTO_IPV6, IPV6_RECVTCLASS, 1) or die("err");
36
37$r = socket_sendmsg($sends1, [
38	"name" => [ "addr" => "::1", "port" => 3000],
39	"iov" => ["test ", "thing", "\n"],
40	"control" => [[
41		"level" => IPPROTO_IPV6,
42		"type" => IPV6_PKTINFO,
43		"data" => [
44			'addr' => '::1',
45            'ifindex' => 1 /* we're assuming loopback is 1. Is this a safe assumption? */
46		],
47	]]
48], 0);
49var_dump($r);
50checktimeout($s, 500);
51
52$data = [
53    "name" => ["family" => AF_INET6, "addr" => "::1"],
54    "buffer_size" => 2000,
55    "controllen" => socket_cmsg_space(IPPROTO_IPV6, IPV6_PKTINFO) +
56			socket_cmsg_space(IPPROTO_IPV6, IPV6_TCLASS),
57];
58if (!socket_recvmsg($s, $data, 0)) die("recvmsg");
59print_r($data);
60
61--EXPECTF--
62creating send socket
63resource(5) of type (Socket)
64bool(true)
65creating receive socket
66resource(6) of type (Socket)
67bool(true)
68int(11)
69Array
70(
71    [name] => Array
72        (
73            [family] => %d
74            [addr] => ::1
75            [port] => 7001
76            [flowinfo] => 0
77            [scope_id] => 0
78        )
79
80    [control] => Array
81        (
82            [0] => Array
83                (
84                    [level] => %d
85                    [type] => %d
86                    [data] => Array
87                        (
88                            [addr] => ::1
89                            [ifindex] => %d
90                        )
91
92                )
93
94            [1] => Array
95                (
96                    [level] => %d
97                    [type] => %d
98                    [data] => 0
99                )
100
101        )
102
103    [iov] => Array
104        (
105            [0] => test thing
106
107        )
108
109    [flags] => 0
110)
111