MCPcopy Index your code
hub / github.com/retspen/webvirtcloud / _checkNetmask

Function _checkNetmask

vrtManager/IPy.py:1245–1262  ·  view source on GitHub ↗

Checks if a netmask is expressable as a prefixlen.

(netmask, masklen)

Source from the content-addressed store, hash-verified

1243
1244
1245def _checkNetmask(netmask, masklen):
1246 """Checks if a netmask is expressable as a prefixlen."""
1247
1248 num = long(netmask)
1249 bits = masklen
1250
1251 # remove zero bits at the end
1252 while (num & 1) == 0 and bits != 0:
1253 num = num >> 1
1254 bits -= 1
1255 if bits == 0:
1256 break
1257 # now check if the rest consists only of ones
1258 while bits > 0:
1259 if (num & 1) == 0:
1260 raise ValueError, "Netmask %s can't be expressed as an prefix." % (hex(netmask))
1261 num = num >> 1
1262 bits -= 1
1263
1264
1265def _checkNetaddrWorksWithPrefixlen(net, prefixlen, version):

Callers 1

_netmaskToPrefixlenFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected