1--TEST--
2pcntl_unshare() with CLONE_NEWNET
3--SKIPIF--
4<?php
5if (!extension_loaded("pcntl")) die("skip");
6if (!extension_loaded("posix")) die("skip posix extension not available");
7if (!function_exists("pcntl_unshare")) die("skip pcntl_unshare is not available");
8if (!defined("CLONE_NEWNET")) die("skip flag unavailable");
9if (posix_getuid() !== 0 &&
10    (!defined("CLONE_NEWUSER") ||
11    (pcntl_unshare(CLONE_NEWUSER) == false && pcntl_get_last_error() == PCNTL_EPERM))) {
12    die("skip Insufficient privileges for CLONE_NEWUSER");
13}
14if (@pcntl_unshare(CLONE_NEWNET) == false && pcntl_get_last_error() == PCNTL_EPERM) {
15    die("skip Insufficient privileges for CLONE_NEWPID");
16}
17if (getenv("SKIP_ONLINE_TESTS")) die("skip online test");
18?>
19--FILE--
20<?php
21
22if(posix_getuid() !== 0) {
23    pcntl_unshare(CLONE_NEWUSER);
24}
25
26var_dump(gethostbyname('php.net'));
27pcntl_unshare(CLONE_NEWNET);
28var_dump(gethostbyname('php.net'));
29?>
30--EXPECTF--
31string(%d) %s
32string(7) "php.net"
33