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