1--TEST--
2recvmsg(): basic test
3--SKIPIF--
4<?php
5if (!extension_loaded('sockets')) {
6    die('skip sockets extension not available.');
7}
8
9require 'ipv6_skipif.inc';
10
11if (!defined('IPPROTO_IPV6')) {
12    die('skip IPv6 not available.');
13}
14if (!defined('IPV6_RECVPKTINFO')) {
15    die('skip IPV6_RECVPKTINFO not available.');
16}
17?>
18--FILE--
19<?php
20include __DIR__."/mcast_helpers.php.inc";
21$addr = '::1';
22
23echo "creating send socket\n";
24$sends1 = socket_create(AF_INET6, SOCK_DGRAM, SOL_UDP) or die("err");
25var_dump($sends1);
26$br = socket_bind($sends1, '::', 7001) or die("err");
27var_dump($br);
28socket_set_nonblock($sends1) or die("Could not put in non-blocking mode");
29
30echo "creating receive socket\n";
31$s = socket_create(AF_INET6, SOCK_DGRAM, SOL_UDP) or die("err");
32var_dump($s);
33$br = socket_bind($s, '::0', 3000) or die("err");
34var_dump($br);
35
36socket_set_option($s, IPPROTO_IPV6, IPV6_RECVPKTINFO, 1) or die("err");
37
38$r = socket_sendto($sends1, $m = "testing packet", strlen($m), 0, $addr, 3000);
39var_dump($r);
40if ($r < 12) die;
41checktimeout($s, 500);
42
43$data = [
44    "name" => ["family" => AF_INET6, "addr" => "::1"],
45    "buffer_size" => 2000,
46    "controllen" => socket_cmsg_space(IPPROTO_IPV6, IPV6_PKTINFO),
47];
48if (!socket_recvmsg($s, $data, 0)) die("recvmsg");
49print_r($data);
50--EXPECTF--
51creating send socket
52resource(%d) of type (Socket)
53bool(true)
54creating receive socket
55resource(%d) of type (Socket)
56bool(true)
57int(14)
58Array
59(
60    [name] => Array
61        (
62            [family] => %d
63            [addr] => ::1
64            [port] => 7001
65            [flowinfo] => 0
66            [scope_id] => 0
67        )
68
69    [control] => Array
70        (
71            [0] => Array
72                (
73                    [level] => %d
74                    [type] => %d
75                    [data] => Array
76                        (
77                            [addr] => ::1
78                            [ifindex] => %d
79                        )
80
81                )
82
83        )
84
85    [iov] => Array
86        (
87            [0] => testing packet
88        )
89
90    [flags] => 0
91)
92