mirror of
https://github.com/billz/raspap-webgui.git
synced 2023-10-10 13:37:24 +02:00
Added cidr2mask()
This commit is contained in:
parent
5cc7794cb0
commit
5b1325803a
@ -1,6 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Functions for Networking */
|
/* Functions for Networking */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a netmask to CIDR notation string
|
||||||
|
*
|
||||||
|
* @param string $mask
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
function mask2cidr($mask)
|
function mask2cidr($mask)
|
||||||
{
|
{
|
||||||
$long = ip2long($mask);
|
$long = ip2long($mask);
|
||||||
@ -8,6 +14,21 @@ function mask2cidr($mask)
|
|||||||
return 32-log(($long ^ $base)+1, 2);
|
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 */
|
/* Functions to write ini files */
|
||||||
|
|
||||||
function write_php_ini($array, $file)
|
function write_php_ini($array, $file)
|
||||||
|
Loading…
Reference in New Issue
Block a user