1--TEST-- 2sendmsg()/recvmsg(): test ability to receive multiple messages 3--SKIPIF-- 4<?php 5if (!extension_loaded('sockets')) 6 die('skip sockets extension not available.'); 7 8require 'ipv6_skipif.inc'; 9 10if (!defined('IPPROTO_IPV6')) 11 die('skip IPv6 not available.'); 12if (substr(PHP_OS, 0, 3) == 'WIN') 13 die('skip Not for the Windows!'); 14/* Windows supports IPV6_RECVTCLASS and is able to receive the tclass via 15 * WSARecvMsg (though only the top 6 bits seem to reported), but WSASendMsg 16 * does not accept IPV6_TCLASS messages */ 17 18if (!defined('IPV6_RECVPKTINFO')) { 19 die('skip IPV6_RECVPKTINFO not available.'); 20} 21?> 22--FILE-- 23<?php 24include __DIR__."/mcast_helpers.php.inc"; 25$addr = '::1'; 26 27echo "creating send socket\n"; 28$sends1 = socket_create(AF_INET6, SOCK_DGRAM, SOL_UDP) or die("err"); 29var_dump($sends1); 30$br = socket_bind($sends1, '::', 7001) or die("err"); 31var_dump($br); 32socket_set_nonblock($sends1) or die("Could not put in non-blocking mode"); 33 34echo "creating receive socket\n"; 35$s = socket_create(AF_INET6, SOCK_DGRAM, SOL_UDP) or die("err"); 36var_dump($s); 37$br = socket_bind($s, '::0', 3000) or die("err"); 38var_dump($br); 39 40socket_set_option($s, IPPROTO_IPV6, IPV6_RECVPKTINFO, 1) or die("err"); 41socket_set_option($s, IPPROTO_IPV6, IPV6_RECVTCLASS, 1) or die("err"); 42 43$r = socket_sendmsg($sends1, [ 44 "name" => [ "addr" => "::1", "port" => 3000], 45 "iov" => ["test ", "thing", "\n"], 46 "control" => [[ 47 "level" => IPPROTO_IPV6, 48 "type" => IPV6_TCLASS, 49 "data" => 40, 50 ]] 51], 0); 52var_dump($r); 53checktimeout($s, 500); 54 55$data = [ 56 "name" => ["family" => AF_INET6, "addr" => "::1"], 57 "buffer_size" => 2000, 58 "controllen" => socket_cmsg_space(IPPROTO_IPV6, IPV6_PKTINFO) + 59 socket_cmsg_space(IPPROTO_IPV6, IPV6_TCLASS), 60]; 61if (!socket_recvmsg($s, $data, 0)) die("recvmsg"); 62print_r($data); 63--EXPECTF-- 64creating send socket 65resource(5) of type (Socket) 66bool(true) 67creating receive socket 68resource(6) of type (Socket) 69bool(true) 70int(11) 71Array 72( 73 [name] => Array 74 ( 75 [family] => %d 76 [addr] => ::1 77 [port] => 7001 78 [flowinfo] => 0 79 [scope_id] => 0 80 ) 81 82 [control] => Array 83 ( 84 [0] => Array 85 ( 86 [level] => %d 87 [type] => %d 88 [data] => Array 89 ( 90 [addr] => ::1 91 [ifindex] => %d 92 ) 93 94 ) 95 96 [1] => Array 97 ( 98 [level] => %d 99 [type] => %d 100 [data] => 40 101 ) 102 103 ) 104 105 [iov] => Array 106 ( 107 [0] => test thing 108 109 ) 110 111 [flags] => 0 112) 113