1--TEST--
2ext/sockets - socket_getpeername_ipv6loop - basic test
3--CREDITS--
4# TestFest 2009 - NorwayUG
5# $Id: socket_getpeername_ipv6loop.phpt 494 2009-06-09 20:38:05Z tatjana.andersen@redpill-linpro.com $
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	/* Hold the port associated to address */
19	$port = 31337;
20
21        /* Setup socket server */
22        $server = socket_create(AF_INET6, SOCK_STREAM, getprotobyname('tcp'));
23        if (!$server) {
24                die('Unable to create AF_INET6 socket [server]');
25        }
26
27        if (!socket_bind($server, $localhost, $port)) {
28                die('Unable to bind to '.$localhost.':'.$port);
29        }
30        if (!socket_listen($server, 2)) {
31                die('Unable to listen on socket');
32        }
33
34        /* Connect to it */
35        $client = socket_create(AF_INET6, SOCK_STREAM, getprotobyname('tcp'));
36        if (!$client) {
37                die('Unable to create AF_INET6 socket [client]');
38        }
39        if (!socket_connect($client, $localhost, $port)) {
40                die('Unable to connect to server socket');
41        }
42
43        /* Accept that connection */
44        $socket = socket_accept($server);
45        if (!$socket) {
46	        die('Unable to accept connection');
47        }
48
49	if (!socket_getpeername($client, $address, $port)) {
50	   	die('Unable to retrieve peer name');
51	}
52        var_dump($address, $port);
53
54        socket_close($client);
55        socket_close($socket);
56        socket_close($server);
57?>
58--EXPECT--
59string(3) "::1"
60int(31337)
61