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 41$r = socket_set_option($s, $level, IP_MULTICAST_TTL, 256); 42var_dump($r); 43$r = socket_get_option($s, $level, IP_MULTICAST_TTL); 44var_dump($r); 45echo "\n"; 46 47echo "Setting IP_MULTICAST_TTL with \"254\"\n"; 48$r = socket_set_option($s, $level, IP_MULTICAST_TTL, "254"); 49var_dump($r); 50$r = socket_get_option($s, $level, IP_MULTICAST_TTL); 51var_dump($r); 52echo "\n"; 53 54echo "Setting IP_MULTICAST_TTL with -1\n"; 55//should give error, not be the same as 255 56$r = socket_set_option($s, $level, IP_MULTICAST_TTL, -1); 57var_dump($r); 58$r = socket_get_option($s, $level, IP_MULTICAST_TTL); 59var_dump($r); 60echo "\n"; 61--EXPECTF-- 62Setting IP_MULTICAST_LOOP with 256 63bool(true) 64int(1) 65 66Setting IP_MULTICAST_LOOP with false 67bool(true) 68int(0) 69 70Setting IP_MULTICAST_TTL with 256 71 72Warning: socket_set_option(): Expected a value between 0 and 255 in %s on line %d 73bool(false) 74int(1) 75 76Setting IP_MULTICAST_TTL with "254" 77bool(true) 78int(254) 79 80Setting IP_MULTICAST_TTL with -1 81 82Warning: socket_set_option(): Expected a value between 0 and 255 in %s on line %d 83bool(false) 84int(254) 85