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} 14if (!defined('SO_PASSCRED')) { 15die('skip SO_PASSCRED is not defined'); 16} 17--CLEAN-- 18<?php 19$path = __DIR__ . "/socket_cmsg_credentials.sock"; 20@unlink($path); 21--FILE-- 22<?php 23include __DIR__."/mcast_helpers.php.inc"; 24$path = __DIR__ . "/socket_cmsg_credentials.sock"; 25 26@unlink($path); 27 28echo "creating send socket\n"; 29$sends1 = socket_create(AF_UNIX, SOCK_DGRAM, 0) or die("err"); 30var_dump($sends1); 31socket_set_nonblock($sends1) or die("Could not put in non-blocking mode"); 32 33echo "creating receive socket\n"; 34$s = socket_create(AF_UNIX, SOCK_DGRAM, 0) or die("err"); 35var_dump($s); 36$br = socket_bind($s, $path) or die("err"); 37var_dump($br); 38socket_set_nonblock($sends1) or die("Could not put in non-blocking mode"); 39socket_set_option($s, SOL_SOCKET, SO_PASSCRED, 1) or die("could not set SO_PASSCRED"); 40 41 42//$r = socket_sendmsg($sends1, [ 43// "iov" => ["test ", "thing", "\n"], 44//], 0); 45$r = socket_sendto($sends1, $msg = "dread", strlen($msg), 0, $path); 46var_dump($r); 47checktimeout($s, 500); 48 49$data = [ 50 "name" => [], 51 "buffer_size" => 2000, 52 "controllen" => socket_cmsg_space(SOL_SOCKET, SCM_CREDENTIALS) 53]; 54if (!socket_recvmsg($s, $data, 0)) die("recvmsg"); 55print_r($data); 56 57$pid = getmypid(); 58var_dump($data['control'][0]['data']['pid'] === $pid); 59--EXPECTF-- 60creating send socket 61resource(%d) of type (Socket) 62creating receive socket 63resource(%d) of type (Socket) 64bool(true) 65int(5) 66Array 67( 68 [name] => 69 [control] => Array 70 ( 71 [0] => Array 72 ( 73 [level] => %d 74 [type] => %d 75 [data] => Array 76 ( 77 [pid] => %d 78 [uid] => %d 79 [gid] => %d 80 ) 81 82 ) 83 84 ) 85 86 [iov] => Array 87 ( 88 [0] => dread 89 ) 90 91 [flags] => 0 92) 93bool(true) 94