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