Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add safe inet_pton #428

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions generator/config/specialCasesFunctions.php
Expand Up @@ -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',
];
17 changes: 17 additions & 0 deletions lib/special_cases.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions rector-migrate.php
Expand Up @@ -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',
Expand Down