diff --git a/generator/config/specialCasesFunctions.php b/generator/config/specialCasesFunctions.php index 31febcc4..217c9512 100644 --- a/generator/config/specialCasesFunctions.php +++ b/generator/config/specialCasesFunctions.php @@ -16,4 +16,5 @@ 'simplexml_load_file', 'simplexml_load_string', 'fgetcsv', // This function need to return false when iterating on an end of file. + 'inet_pton', ]; diff --git a/lib/special_cases.php b/lib/special_cases.php index a4e85a93..890e49dc 100644 --- a/lib/special_cases.php +++ b/lib/special_cases.php @@ -8,6 +8,8 @@ namespace Safe; use Safe\Exceptions\FilesystemException; +use Safe\Exceptions\NetworkException; +use function error_clear_last; use const PREG_NO_ERROR; use Safe\Exceptions\MiscException; @@ -440,3 +442,18 @@ function fgetcsv($stream, int $length = null, string $separator = ",", string $e } return $safeResult; } + +/** + * @param string $ip A human readable IPv4 or IPv6 address. + * @return string Returns the in_addr representation of the given ip, + * @throws NetworkException + */ +function inet_pton(string $ip): string +{ + error_clear_last(); + $safeResult = \inet_pton($ip); + if ($safeResult === false) { + throw NetworkException::createFromPhpError(); + } + return $safeResult; +} diff --git a/rector-migrate.php b/rector-migrate.php index 8bd9d7bd..aa0c52dd 100644 --- a/rector-migrate.php +++ b/rector-migrate.php @@ -447,6 +447,7 @@ 'imap_unsubscribe' => 'Safe\imap_unsubscribe', 'imap_utf8_to_mutf7' => 'Safe\imap_utf8_to_mutf7', 'inet_ntop' => 'Safe\inet_ntop', + 'inet_pton' => 'Safe\inet_pton', 'inflate_add' => 'Safe\inflate_add', 'inflate_get_read_len' => 'Safe\inflate_get_read_len', 'inflate_get_status' => 'Safe\inflate_get_status',