1--TEST--
2recvmsg(): receive SCM_CREDS messages
3--EXTENSIONS--
4sockets
5--SKIPIF--
6<?php
7
8if (!str_contains(PHP_OS, 'FreeBSD')) {
9    die('skipped supported only on FreeBSD');
10}
11--FILE--
12<?php
13include __DIR__."/mcast_helpers.php.inc";
14$path = __DIR__ . "/socket_cmsg_credentials_fbsd.sock";
15
16@unlink($path);
17
18echo "creating send socket\n";
19$sends1 = socket_create(AF_UNIX, SOCK_DGRAM, 0) or die("err");
20var_dump($sends1);
21socket_set_nonblock($sends1) or die("Could not put in non-blocking mode");
22
23echo "creating receive socket\n";
24$s = socket_create(AF_UNIX, SOCK_DGRAM, 0) or die("err");
25var_dump($s);
26$br = socket_bind($s, $path) or die("err");
27var_dump($br);
28socket_set_nonblock($s) or die("Could not put in non-blocking mode");
29socket_set_option($s, SOL_LOCAL, LOCAL_CREDS_PERSISTENT, 1) or die("could not set LOCAL_CREDS");
30
31
32$r = socket_sendto($sends1, $msg = "dread", strlen($msg), 0, $path);
33var_dump($r);
34checktimeout($s, 500);
35
36$data = [
37    "name" => [],
38    "buffer_size" => 2000,
39    "controllen" => socket_cmsg_space(SOL_SOCKET, SCM_CREDS2, 1)
40];
41if (!socket_recvmsg($s, $data, 0)) die("recvmsg");
42print_r($data);
43
44$pid = getmypid();
45var_dump($data['control'][0]['data']['pid'] === $pid);
46?>
47--CLEAN--
48<?php
49$path = __DIR__ . "/socket_cmsg_credentials_fbsd.sock";
50@unlink($path);
51--EXPECTF--
52creating send socket
53object(Socket)#%d (0) {
54}
55creating receive socket
56object(Socket)#%d (0) {
57}
58bool(true)
59int(5)
60Array
61(
62    [name] => Array
63        (
64            [family] => %d
65            [path] =>
66        )
67
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