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