CFLib.org – Common Function Library Project

cidrToNetMask(cidr)

Last updated July 19, 2005
Download UDF

author

Sufiyan bin Yasa                                  Sufiyan bin Yasa

Version: 1 | Requires: ColdFusion 5 | 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:

<cfscript>
/**
* 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;
}
</cfscript>

Search CFLib.org


Latest Additions

Raymond Compton Raymond Compton added
structBlend
20 day(s) ago

Duncan Duncan added
IsZIPUK
20 day(s) ago

Todd Sharp Todd Sharp added
getTagContentAll
26 day(s) ago

Gerald Guido Gerald Guido added
ListReturnDuplicat...
1 month(s) ago

Gerald Guido Gerald Guido added
ListReturnDuplicat...
1 month(s) ago

Created by Raymond Camden / Design by Justin Johnson