1--TEST--
2recvmsg(): receive SCM_CREDENTIALS messages
3--SKIPIF--
4<?php
5if (!extension_loaded('sockets')) {
6die('skip sockets extension not available.');
7}
8if (strtolower(substr(PHP_OS, 0, 3)) == 'win') {
9die('skip not for Microsoft Windows');
10}
11if (strtolower(substr(PHP_OS, 0, 3)) == 'aix') {
12die('skip not for AIX');
13}
14--CLEAN--
15<?php
16$path = __DIR__ . "/unix_sock";
17@unlink($path);
18
19--FILE--
20<?php
21include __DIR__."/mcast_helpers.php.inc";
22$path = __DIR__ . "/unix_sock";
23
24@unlink($path);
25
26echo "creating send socket\n";
27$sends1 = socket_create(AF_UNIX, SOCK_DGRAM, 0) or die("err");
28var_dump($sends1);
29socket_set_nonblock($sends1) or die("Could not put in non-blocking mode");
30
31echo "creating receive socket\n";
32$s = socket_create(AF_UNIX, SOCK_DGRAM, 0) or die("err");
33var_dump($s);
34$br = socket_bind($s, $path) or die("err");
35var_dump($br);
36socket_set_nonblock($s) or die("Could not put in non-blocking mode");
37
38$r = socket_sendmsg($sends1, [
39  "name" => [ "path" => $path ],
40  "iov" => ["test ", "thing", "\n"],
41  "control" => [
42    [
43      "level" => SOL_SOCKET,
44      "type" => SCM_RIGHTS,
45      "data" => [$sends1, STDIN, STDOUT, STDERR],
46    ]
47  ]
48], 0);
49var_dump($r);
50checktimeout($s, 500);
51
52$data = [
53    "name" => [],
54    "buffer_size" => 2000,
55    "controllen" => socket_cmsg_space(SOL_SOCKET, SCM_RIGHTS, 4)
56];
57var_dump($data);
58if (!socket_recvmsg($s, $data, 0)) die("recvmsg");
59print_r($data);
60--EXPECTF--
61creating send socket
62resource(%d) of type (Socket)
63creating receive socket
64resource(%d) of type (Socket)
65bool(true)
66int(11)
67array(3) {
68  ["name"]=>
69  array(0) {
70  }
71  ["buffer_size"]=>
72  int(2000)
73  ["controllen"]=>
74  int(%d)
75}
76Array
77(
78    [name] =>
79    [control] => Array
80        (
81            [0] => Array
82                (
83                    [level] => %d
84                    [type] => %d
85                    [data] => Array
86                        (
87                            [0] => Resource id #%d
88                            [1] => Resource id #%d
89                            [2] => Resource id #%d
90                            [3] => Resource id #%d
91                        )
92
93                )
94
95        )
96
97    [iov] => Array
98        (
99            [0] => test thing
100
101        )
102
103    [flags] => 0
104)
105