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?>
62--EXPECTF--
63creating send socket
64object(Socket)#%d (0) {
65}
66bool(true)
67creating receive socket
68object(Socket)#%d (0) {
69}
70bool(true)
71int(11)
72Array
73(
74    [name] => Array
75        (
76            [family] => %d
77            [addr] => ::1
78            [port] => 7003
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] => 0
102                )
103
104        )
105
106    [iov] => Array
107        (
108            [0] => test thing
109
110        )
111
112    [flags] => 0
113)
114