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 56--EXPECTF-- 57Setting IP_MULTICAST_LOOP with 256 58bool(true) 59int(1) 60 61Setting IP_MULTICAST_LOOP with false 62bool(true) 63int(0) 64 65Setting IP_MULTICAST_TTL with 256 66 67Warning: socket_set_option(): Expected a value between 0 and 255 in %s on line %d 68bool(false) 69int(1) 70 71Setting IP_MULTICAST_TTL with "254" 72bool(true) 73int(254) 74 75Setting IP_MULTICAST_TTL with -1 76 77Warning: socket_set_option(): Expected a value between 0 and 255 in %s on line %d 78bool(false) 79int(254) 80