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