xref: /PHP-8.0/ext/standard/tests/network/inet.phpt (revision 5dafd7b4)
1--TEST--
2inet_ntop() & inet_pton() tests
3--SKIPIF--
4<?php
5if (!function_exists("inet_ntop")) die("skip no inet_ntop()");
6if (!function_exists("inet_pton")) die("skip no inet_pton()");
7?>
8--FILE--
9<?php
10
11$packed = chr(127) . chr(0) . chr(0) . chr(1);
12var_dump(inet_ntop($packed));
13
14$packed = chr(255) . chr(255) . chr(255) . chr(0);
15var_dump(inet_ntop($packed));
16
17var_dump(inet_ntop(-1));
18var_dump(inet_ntop(""));
19var_dump(inet_ntop("blah-blah"));
20
21var_dump(inet_pton(""));
22var_dump(inet_pton(-1));
23var_dump(inet_pton("abra"));
24
25$array = array(
26    "127.0.0.1",
27    "66.163.161.116",
28    "255.255.255.255",
29    "0.0.0.0",
30    );
31foreach ($array as $val) {
32    var_dump(bin2hex($packed = inet_pton($val)));
33    var_dump(inet_ntop($packed));
34}
35
36echo "Done\n";
37?>
38--EXPECT--
39string(9) "127.0.0.1"
40string(13) "255.255.255.0"
41bool(false)
42bool(false)
43bool(false)
44bool(false)
45bool(false)
46bool(false)
47string(8) "7f000001"
48string(9) "127.0.0.1"
49string(8) "42a3a174"
50string(14) "66.163.161.116"
51string(8) "ffffffff"
52string(15) "255.255.255.255"
53string(8) "00000000"
54string(7) "0.0.0.0"
55Done
56