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
51--EXPECTF--
52creating send socket
53resource(%d) of type (Socket)
54bool(true)
55creating receive socket
56resource(%d) of type (Socket)
57bool(true)
58int(14)
59Array
60(
61    [name] => Array
62        (
63            [family] => %d
64            [addr] => ::1
65            [port] => 7001
66            [flowinfo] => 0
67            [scope_id] => 0
68        )
69
70    [control] => Array
71        (
72            [0] => Array
73                (
74                    [level] => %d
75                    [type] => %d
76                    [data] => Array
77                        (
78                            [addr] => ::1
79                            [ifindex] => %d
80                        )
81
82                )
83
84        )
85
86    [iov] => Array
87        (
88            [0] => testing packet
89        )
90
91    [flags] => 0
92)
93