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