cidrToNetMask(cidr)
Last updated July 20, 2005
Version: 1 | Requires: CF5 | Library: NetLib
Description:
CIDR numbers such as /24,/32,/12 are converted to the appropiate netmask address form.
Return Values:
Returns a string.
Example:
#cidrToNetMask(24)#<br>
#cidrToNetMask(12)#<br>
Parameters:
Name | Description | Required |
---|---|---|
cidr | CIDR number. | Yes |
Full UDF Source:
/**
* Converts CIDR numbers to valid network mask numbers.
*
* @param cidr CIDR number. (Required)
* @return Returns a string.
* @author Sufiyan bin Yasa (cinod_79@yahoo.com)
* @version 1, July 19, 2005
*/
function cidrToNetMask (cidr) {
var netMask = "";
var post = 0;
var remainder = cidr MOD 8;
var divide = cidr \ 8;
while(divide gt 0) {
netMask = listAppend(netMask, 255,'.');
divide = divide - 1;
post = post + 1;
}
if(remainder gt 0) {
netMask = listAppend(NetMask,
bitSHLN(BitOr(0,2^remainder-1), 8-remainder),
'.');
post = post +1;
}
while(post lt 4) {
netMask = listAppend(netMask, "0",'.');
post = post + 1;
}
if(right(netMask, 1) eq "."){
netMask = left(netMask,len(netMask));
}
return netMask;
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016