mirror of
https://github.com/RaspAP/raspap-webgui.git
synced 2024-11-22 07:30:23 +00:00
Added cidr2mask()
This commit is contained in:
parent
5cc7794cb0
commit
5b1325803a
1 changed files with 21 additions and 0 deletions
|
@ -1,6 +1,12 @@
|
|||
<?php
|
||||
/* Functions for Networking */
|
||||
|
||||
/**
|
||||
* Converts a netmask to CIDR notation string
|
||||
*
|
||||
* @param string $mask
|
||||
* @return string
|
||||
*/
|
||||
function mask2cidr($mask)
|
||||
{
|
||||
$long = ip2long($mask);
|
||||
|
@ -8,6 +14,21 @@ function mask2cidr($mask)
|
|||
return 32-log(($long ^ $base)+1, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a CIDR notation string to a netmask
|
||||
*
|
||||
* @param string $cidr
|
||||
* @return string
|
||||
*/
|
||||
function cidr2mask($cidr)
|
||||
{
|
||||
$ta = substr ($cidr, strpos ($cidr, '/') + 1) * 1;
|
||||
$netmask = str_split (str_pad (str_pad ('', $ta, '1'), 32, '0'), 8);
|
||||
foreach ($netmask as &$element)
|
||||
$element = bindec ($element);
|
||||
return join ('.', $netmask);
|
||||
}
|
||||
|
||||
/* Functions to write ini files */
|
||||
|
||||
function write_php_ini($array, $file)
|
||||
|
|
Loading…
Reference in a new issue