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($sends1) or die("Could not put in non-blocking mode");
37socket_set_option($s, SOL_SOCKET, SO_PASSCRED, 1) or die("could not set SO_PASSCRED");
38
39
40//$r = socket_sendmsg($sends1, [
41//  "iov" => ["test ", "thing", "\n"],
42//], 0);
43$r = socket_sendto($sends1, $msg = "dread", strlen($msg), 0, $path);
44var_dump($r);
45checktimeout($s, 500);
46
47$data = [
48    "name" => [],
49    "buffer_size" => 2000,
50    "controllen" => socket_cmsg_space(SOL_SOCKET, SCM_CREDENTIALS)
51];
52if (!socket_recvmsg($s, $data, 0)) die("recvmsg");
53print_r($data);
54
55$pid = getmypid();
56var_dump($data['control'][0]['data']['pid'] === $pid);
57
58--EXPECTF--
59creating send socket
60resource(%d) of type (Socket)
61creating receive socket
62resource(%d) of type (Socket)
63bool(true)
64int(5)
65Array
66(
67    [name] =>
68    [control] => Array
69        (
70            [0] => Array
71                (
72                    [level] => %d
73                    [type] => %d
74                    [data] => Array
75                        (
76                            [pid] => %d
77                            [uid] => %d
78                            [gid] => %d
79                        )
80
81                )
82
83        )
84
85    [iov] => Array
86        (
87            [0] => dread
88        )
89
90    [flags] => 0
91)
92bool(true)
93