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.');
7
8require 'ipv6_skipif.inc';
9
10if (!defined('IPPROTO_IPV6'))
11	die('skip IPv6 not available.');
12/* Windows supports IPV6_RECVTCLASS and is able to receive the tclass via
13 * WSARecvMsg (though only the top 6 bits seem to reported), but WSASendMsg
14 * does not accept IPV6_TCLASS messages. We still test that sendmsg() works
15 * correctly by sending an IPV6_PKTINFO message that will have no effect */
16?>
17--FILE--
18<?php
19include __DIR__."/mcast_helpers.php.inc";
20$addr = '::1';
21
22echo "creating send socket\n";
23$sends1 = socket_create(AF_INET6, SOCK_DGRAM, SOL_UDP) or die("err");
24var_dump($sends1);
25$br = socket_bind($sends1, '::', 7003) or die("err");
26var_dump($br);
27socket_set_nonblock($sends1) or die("Could not put in non-blocking mode");
28
29echo "creating receive socket\n";
30$s = socket_create(AF_INET6, SOCK_DGRAM, SOL_UDP) or die("err");
31var_dump($s);
32$br = socket_bind($s, '::0', 3003) or die("err");
33var_dump($br);
34
35socket_set_option($s, IPPROTO_IPV6, IPV6_RECVPKTINFO, 1) or die("err");
36socket_set_option($s, IPPROTO_IPV6, IPV6_RECVTCLASS, 1) or die("err");
37
38$r = socket_sendmsg($sends1, [
39	"name" => [ "addr" => "::1", "port" => 3003],
40	"iov" => ["test ", "thing", "\n"],
41	"control" => [[
42		"level" => IPPROTO_IPV6,
43		"type" => IPV6_PKTINFO,
44		"data" => [
45			'addr' => '::1',
46            'ifindex' => 1 /* we're assuming loopback is 1. Is this a safe assumption? */
47		],
48	]]
49], 0);
50var_dump($r);
51checktimeout($s, 500);
52
53$data = [
54    "name" => ["family" => AF_INET6, "addr" => "::1"],
55    "buffer_size" => 2000,
56    "controllen" => socket_cmsg_space(IPPROTO_IPV6, IPV6_PKTINFO) +
57			socket_cmsg_space(IPPROTO_IPV6, IPV6_TCLASS),
58];
59if (!socket_recvmsg($s, $data, 0)) die("recvmsg");
60print_r($data);
61--EXPECTF--
62creating send socket
63resource(%d) of type (Socket)
64bool(true)
65creating receive socket
66resource(%d) of type (Socket)
67bool(true)
68int(11)
69Array
70(
71    [name] => Array
72        (
73            [family] => %d
74            [addr] => ::1
75            [port] => 7003
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