(netmask, masklen)
Checks if a netmask is expressable as e prefixlen.
Checks if a netmask is expressable as e prefixlen.
Checks if a netmask is expressable as e prefixlen .
def _checkNetmask(netmask, masklen):
    """Checks if a netmask is expressable as e prefixlen."""

    num = long(netmask)
    bits = masklen

    # remove zero bits at the end
    while (num & 1) == 0:
        num = num >> 1
        bits -= 1
        if bits == 0:
            break
    # now check if the rest consists only of ones
    while bits > 0:
        if (num & 1) == 0:
            raise ValueError(
                "Netmask %s can't be expressed as an prefix." %
                (hex(netmask)))
        num = num >> 1
        bits -= 1
def _checkNetmask ( netmask , masklen ) : num = long ( netmask ) bits = masklen # remove zero bits at the end while ( num & 1 ) == 0 : num = num >> 1 bits -= 1 if bits == 0 : break # now check if the rest consists only of ones while bits > 0 : if ( num & 1 ) == 0 : raise ValueError ( "Netmask %s can't be expressed as an prefix." % ( hex ( netmask ) ) ) num = num >> 1 bits -= 1