summaryrefslogtreecommitdiff
path: root/ext/standard/tests/network/inet.phpt
blob: 29b4aa0e6be970422b6f590e3483bc391ea2f504 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
--TEST--
inet_ntop() & inet_pton() tests
--SKIPIF--
<?php
if (!function_exists("inet_ntop")) die("skip no inet_ntop()");
if (!function_exists("inet_pton")) die("skip no inet_pton()");
?>
--FILE--
<?php

$packed = chr(127) . chr(0) . chr(0) . chr(1);
var_dump(inet_ntop($packed));

$packed = chr(255) . chr(255) . chr(255) . chr(0);
var_dump(inet_ntop($packed));

var_dump(inet_ntop(-1));
var_dump(inet_ntop(""));
var_dump(inet_ntop("blah-blah"));

var_dump(inet_pton(""));
var_dump(inet_pton(-1));
var_dump(inet_pton("abra"));

$array = array(
    "127.0.0.1",
    "66.163.161.116",
    "255.255.255.255",
    "0.0.0.0",
    );
foreach ($array as $val) {
    var_dump(bin2hex($packed = inet_pton($val)));
    var_dump(inet_ntop($packed));
}

echo "Done\n";
?>
--EXPECTF--
string(9) "127.0.0.1"
string(13) "255.255.255.0"
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
string(8) "7f000001"
string(9) "127.0.0.1"
string(8) "42a3a174"
string(14) "66.163.161.116"
string(8) "ffffffff"
string(15) "255.255.255.255"
string(8) "00000000"
string(7) "0.0.0.0"
Done