Created
July 11, 2014 15:42
-
-
Save realeroberto/5394beeb2173f7b74f9e to your computer and use it in GitHub Desktop.
Convert a Classless Inter-Domain Routing prefix to a plain old network mask.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Convert a Classless Inter-Domain Routing prefix to a plain old network mask. | |
* | |
* E.g.: 24 => 255.255.255.0 | |
*/ | |
function cidr_prefix_to_netmask($prefix) | |
{ | |
for ($i = 0, $netmask = 0; $i <= (int)$prefix; $i++, $netmask += 2 << (32 - $i)); | |
return long2ip($netmask); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment