Skip to content

Commit

Permalink
Add safe inet_pton
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Oct 23, 2023
1 parent 3a6e43b commit ab07c62
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions generator/config/specialCasesFunctions.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit ab07c62

Please sign in to comment.