blob: 125bd15fb3bc288052f02ce3293cb0f650099b53 (
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
56
57
58
59
60
61
62
63
64
65
|
--TEST--
inet_ntop() & inet_pton() IPv6 tests
--SKIPIF--
<?php
if (!function_exists("inet_ntop")) die("skip no inet_ntop()");
if (!function_exists("inet_pton")) die("skip no inet_pton()");
$packed = str_repeat(chr(0), 15) . chr(1);
if (@inet_ntop((binary)$packed) === false) {
die("skip no IPv6 support");
}
if (stristr(PHP_OS, "darwin") !== false) die("skip MacOS has broken inet_*() funcs");
?>
--FILE--
<?php
$a = array(
'::1',
'::2',
'::35',
'::255',
'::1024',
'',
'2001:0db8:85a3:08d3:1319:8a2e:0370:7344',
'2001:0db8:1234:0000:0000:0000:0000:0000',
'2001:0db8:1234:FFFF:FFFF:FFFF:FFFF:FFFF',
);
foreach ($a as $address) {
$packed = inet_pton($address);
var_dump(inet_ntop($packed));
}
echo "Done\n";
?>
--EXPECTF--
string(3) "::1"
string(3) "::2"
string(4) "::35"
string(5) "::255"
string(6) "::1024"
Warning: inet_pton(): Unrecognized address in %s on line %d
Warning: inet_ntop(): Invalid in_addr value in %s on line %d
bool(false)
string(36) "2001:db8:85a3:8d3:1319:8a2e:370:7344"
string(15) "2001:db8:1234::"
string(38) "2001:db8:1234:ffff:ffff:ffff:ffff:ffff"
Done
--UEXPECTF--
unicode(3) "::1"
unicode(3) "::2"
unicode(4) "::35"
unicode(5) "::255"
unicode(6) "::1024"
Warning: inet_pton(): Unrecognized address in %s on line %d
Warning: inet_ntop(): Invalid in_addr value in %s on line %d
bool(false)
unicode(36) "2001:db8:85a3:8d3:1319:8a2e:370:7344"
unicode(15) "2001:db8:1234::"
unicode(38) "2001:db8:1234:ffff:ffff:ffff:ffff:ffff"
Done
|