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, '::', 7002) 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', 3002) 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" => 3002],
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
66object(Socket)#%d (0) {
67}
68bool(true)
69creating receive socket
70object(Socket)#%d (0) {
71}
72bool(true)
73int(11)
74Array
75(
76    [name] => Array
77        (
78            [family] => %d
79            [addr] => ::1
80            [port] => 7002
81            [flowinfo] => 0
82            [scope_id] => 0
83        )
84
85    [control] => Array
86        (
87            [0] => Array
88                (
89                    [level] => %d
90                    [type] => %d
91                    [data] => Array
92                        (
93                            [addr] => ::1
94                            [ifindex] => %d
95                        )
96
97                )
98
99            [1] => Array
100                (
101                    [level] => %d
102                    [type] => %d
103                    [data] => 40
104                )
105
106        )
107
108    [iov] => Array
109        (
110            [0] => test thing
111
112        )
113
114    [flags] => 0
115)
116