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} 8if (socket_set_option($s, $level, IP_MULTICAST_IF, 1) === false) { 9 die("skip interface 1 either doesn't exist or has no ipv4 address"); 10} 11--FILE-- 12<?php 13$domain = AF_INET; 14$level = IPPROTO_IP; 15$s = socket_create($domain, SOCK_DGRAM, SOL_UDP) or die("err"); 16 17echo "Setting IP_MULTICAST_LOOP with 256\n"; 18//if we had a simple cast to unsigned char, this would be the same as 0 19$r = socket_set_option($s, $level, IP_MULTICAST_LOOP, 256); 20var_dump($r); 21$r = socket_get_option($s, $level, IP_MULTICAST_LOOP); 22var_dump($r); 23echo "\n"; 24 25echo "Setting IP_MULTICAST_LOOP with false\n"; 26//should convert to (unsigned char)0 27$r = socket_set_option($s, $level, IP_MULTICAST_LOOP, false); 28var_dump($r); 29$r = socket_get_option($s, $level, IP_MULTICAST_LOOP); 30var_dump($r); 31echo "\n"; 32 33echo "Setting IP_MULTICAST_TTL with 256\n"; 34//if we had a simple cast to unsigned char, this would be the same as 0 35$r = socket_set_option($s, $level, IP_MULTICAST_TTL, 256); 36var_dump($r); 37$r = socket_get_option($s, $level, IP_MULTICAST_TTL); 38var_dump($r); 39echo "\n"; 40 41echo "Setting IP_MULTICAST_TTL with \"254\"\n"; 42$r = socket_set_option($s, $level, IP_MULTICAST_TTL, "254"); 43var_dump($r); 44$r = socket_get_option($s, $level, IP_MULTICAST_TTL); 45var_dump($r); 46echo "\n"; 47 48echo "Setting IP_MULTICAST_TTL with -1\n"; 49//should give error, not be the same as 255 50$r = socket_set_option($s, $level, IP_MULTICAST_TTL, -1); 51var_dump($r); 52$r = socket_get_option($s, $level, IP_MULTICAST_TTL); 53var_dump($r); 54echo "\n"; 55--EXPECTF-- 56Setting IP_MULTICAST_LOOP with 256 57bool(true) 58int(1) 59 60Setting IP_MULTICAST_LOOP with false 61bool(true) 62int(0) 63 64Setting IP_MULTICAST_TTL with 256 65 66Warning: socket_set_option(): Expected a value between 0 and 255 in %s on line %d 67bool(false) 68int(1) 69 70Setting IP_MULTICAST_TTL with "254" 71bool(true) 72int(254) 73 74Setting IP_MULTICAST_TTL with -1 75 76Warning: socket_set_option(): Expected a value between 0 and 255 in %s on line %d 77bool(false) 78int(254) 79