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