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