1--TEST-- 2Multicast support: IPv4 send options with unusual values 3--SKIPIF-- 4<?php 5if (!extension_loaded('sockets')) { 6 die('skip sockets extension not available.'); 7} 8$domain = AF_INET; 9$level = IPPROTO_IP; 10$s = socket_create($domain, SOCK_DGRAM, SOL_UDP); 11if ($s === false) { 12 die("skip unable to create socket"); 13} 14if (socket_set_option($s, $level, IP_MULTICAST_IF, 1) === false) { 15 die("skip interface 1 either doesn't exist or has no ipv4 address"); 16} 17--FILE-- 18<?php 19$domain = AF_INET; 20$level = IPPROTO_IP; 21$s = socket_create($domain, SOCK_DGRAM, SOL_UDP) or die("err"); 22 23echo "Setting IP_MULTICAST_LOOP with 256\n"; 24//if we had a simple cast to unsigned char, this would be the same as 0 25$r = socket_set_option($s, $level, IP_MULTICAST_LOOP, 256); 26var_dump($r); 27$r = socket_get_option($s, $level, IP_MULTICAST_LOOP); 28var_dump($r); 29echo "\n"; 30 31echo "Setting IP_MULTICAST_LOOP with false\n"; 32//should convert to (unsigned char)0 33$r = socket_set_option($s, $level, IP_MULTICAST_LOOP, false); 34var_dump($r); 35$r = socket_get_option($s, $level, IP_MULTICAST_LOOP); 36var_dump($r); 37echo "\n"; 38 39echo "Setting IP_MULTICAST_TTL with 256\n"; 40//if we had a simple cast to unsigned char, this would be the same as 0 41try { 42 $r = socket_set_option($s, $level, IP_MULTICAST_TTL, 256); 43 var_dump($r); 44} catch (\ValueError $e) { 45 echo $e->getMessage() . \PHP_EOL; 46} 47$r = socket_get_option($s, $level, IP_MULTICAST_TTL); 48var_dump($r); 49echo "\n"; 50 51echo "Setting IP_MULTICAST_TTL with \"254\"\n"; 52$r = socket_set_option($s, $level, IP_MULTICAST_TTL, "254"); 53var_dump($r); 54$r = socket_get_option($s, $level, IP_MULTICAST_TTL); 55var_dump($r); 56echo "\n"; 57 58echo "Setting IP_MULTICAST_TTL with -1\n"; 59//should give error, not be the same as 255 60try { 61 $r = socket_set_option($s, $level, IP_MULTICAST_TTL, -1); 62 var_dump($r); 63} catch (\ValueError $e) { 64 echo $e->getMessage() . \PHP_EOL; 65} 66$r = socket_get_option($s, $level, IP_MULTICAST_TTL); 67var_dump($r); 68echo "\n"; 69?> 70--EXPECT-- 71Setting IP_MULTICAST_LOOP with 256 72bool(true) 73int(1) 74 75Setting IP_MULTICAST_LOOP with false 76bool(true) 77int(0) 78 79Setting IP_MULTICAST_TTL with 256 80socket_set_option(): Argument #4 ($value) must be between 0 and 255 81int(1) 82 83Setting IP_MULTICAST_TTL with "254" 84bool(true) 85int(254) 86 87Setting IP_MULTICAST_TTL with -1 88socket_set_option(): Argument #4 ($value) must be between 0 and 255 89int(254) 90