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