1--TEST-- 2ext/sockets - socket_getpeername_ipv6loop - basic test 3--CREDITS-- 4Tatjana Andersen tatjana.andersen@redpill-linpro.com 5# TestFest 2009 - NorwayUG 6--SKIPIF-- 7<?php 8if (!extension_loaded('sockets')) { 9 die('skip sockets extension not available.'); 10} 11require 'ipv6_skipif.inc'; 12?> 13--FILE-- 14<?php 15 /* Bind and connect sockets to localhost */ 16 $localhost = '::1'; 17 18 /* Setup socket server */ 19 $server = socket_create(AF_INET6, SOCK_STREAM, SOL_TCP); 20 if (!$server) { 21 die('Unable to create AF_INET6 socket [server]'); 22 } 23 24 $minport = 31337; 25 $maxport = 31356; 26 $bound = false; 27 for($port = $minport; $port <= $maxport; ++$port) { 28 if (@socket_bind($server, $localhost, $port)) { 29 $bound = true; 30 break; 31 } 32 } 33 if (!$bound) { 34 die('Unable to bind to '.$localhost); 35 } 36 if (!socket_listen($server, 2)) { 37 die('Unable to listen on socket'); 38 } 39 40 /* Connect to it */ 41 $client = socket_create(AF_INET6, SOCK_STREAM, SOL_TCP); 42 if (!$client) { 43 die('Unable to create AF_INET6 socket [client]'); 44 } 45 if (!socket_connect($client, $localhost, $port)) { 46 die('Unable to connect to server socket'); 47 } 48 49 /* Accept that connection */ 50 $socket = socket_accept($server); 51 if (!$socket) { 52 die('Unable to accept connection'); 53 } 54 55 if (!socket_getpeername($client, $address, $peerport)) { 56 die('Unable to retrieve peer name'); 57 } 58 var_dump($address, $port === $peerport); 59 60 socket_close($client); 61 socket_close($socket); 62 socket_close($server); 63?> 64--EXPECT-- 65string(3) "::1" 66bool(true) 67