Get the netmask for an interface.
        @param ifname: interface name
        @type ifname: string
348428
def getMask (self, ifname):
        
        if sys.platform == 'darwin':
            return ifconfig_inet(ifname).get('netmask')
        return self._getaddr(ifname, self.SIOCGIFNETMASK)
324086
def infer_netmask (addr):
  
  addr = int(addr)
  if addr == 0:
    # Special case -- default network
    return 32-32 # all bits wildcarded
  if (addr & (1 << 31)) == 0:
    # Class A
    return 32-24
  if (addr & (3 << 30)) == 2 << 30:
    # Class B
    return 32-16
  if (addr & (7 << 29)) == 6 << 29:
    # Class C
    return 32-8
  if (addr & (15 << 28)) == 14 << 28:
    # Class D (Multicast)
    return 32-0 # exact match
  # Must be a Class E (Experimental)
  return 32-0
845007
def netmask(mask):
    '''
    
    '''
    if not isinstance(mask, string_types):
        return False

    octets = mask.split('.')
    if not len(octets) == 4:
        return False

    return ipv4_addr(mask) and octets == sorted(octets, reverse=True)
910214
def __ipv4_netmask(value):
    ''''''
    valid, errmsg = False, 'dotted quad or integer CIDR (0->32)'
    valid, value, _ = __int(value)
    if not (valid and 0 <= value <= 32):
        valid = salt.utils.validate.net.netmask(value)
    return (valid, value, errmsg)
402401
def interface_ip(iface):
    '''
    
    '''
    iface_info, error = _get_iface_info(iface)

    if error is False:
        inet = iface_info.get(iface, {}).get('inet', None)
        return inet[0].get('address', '') if inet else ''
    else:
        return error
1105273
def _ip_ifaces():
    '''
    
    '''
    tmp = {}
    ret = {}
    if_ = None
    at_ = None
    out = __salt__['cmd.run']('ip a')
    for line in out.splitlines():
        if not line.startswith(' '):
            comps = line.split(':')
            if_ = comps[1].strip()
            opts_comps = comps[2].strip().split()
            flags = opts_comps.pop(0).lstrip('<').rstrip('>').split(',')
            opts_iter = iter(opts_comps)
            ret[if_] = {
                'flags': flags,
                'options': dict(list(zip(opts_iter, opts_iter)))
            }
        else:
            if line.strip().startswith('link'):
                comps = iter(line.strip().split())
                ret[if_]['link_layer'] = dict(list(zip(comps, comps)))
            elif line.strip().startswith('inet'):
                comps = line.strip().split()
                at_ = comps[0]
                if len(comps) % 2 != 0:
                    last = comps.pop()
                    comps[-1] += ' {0}'.format(last)
                ifi = iter(comps)
                ret[if_][at_] = dict(list(zip(ifi, ifi)))
            else:
                comps = line.strip().split()
                ifi = iter(comps)
                ret[if_][at_].update(dict(list(zip(ifi, ifi))))
    return ret
735566
def _getaddr (self, ifname, func):
        """"""
        try:
            result = self._ioctl(func, self._getifreq(ifname))
        except IOError as msg:
            log.warn(LOG_CHECK,
                  "error getting addr for interface %r: %s", ifname, msg)
            return None
        return socket.inet_ntoa(result[20:24])
487504
def virtual_interface_create(self, name, net_name):
        '''
        
        '''
        nt_ks = self.compute_conn
        serverid = self._server_uuid_from_name(name)
        networkid = self.network_show(net_name).get('id', None)
        if networkid is None:
            return {net_name: False}
        nets = nt_ks.virtual_interfaces.create(networkid, serverid)
        return nets
1372639
def interface(iface):
    '''
    
    '''
    iface_info, error = _get_iface_info(iface)

    if error is False:
        return iface_info.get(iface, {}).get('inet', '')
    else:
        return error
135694
function getAnnouncedIpsForInterface(ifaceName) {
	const addresses = interfaces[ifaceName];

	if (!addresses) {
		throw new Error('Interface ' + ifaceName + ' could not be found');
	}

	const announced = pushIps(addresses, [], true);
	assertNotEmpty(announced, 'Interface ' + ifaceName + ' does not define any IP addresses');

	return announced;
}
233197
def get_alias_address(iface_name, ip_mask, gw_str, metric):
    

    # Detect the architecture
    if scapy.consts.IS_64BITS:
        offset, name_len = 16, 40
    else:
        offset, name_len = 32, 32

    # Retrieve interfaces structures
    sck = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    names = array.array('B', b'\0' * 4096)
    ifreq = ioctl(sck.fileno(), SIOCGIFCONF,
                  struct.pack("iL", len(names), names.buffer_info()[0]))

    # Extract interfaces names
    out = struct.unpack("iL", ifreq)[0]
    names = names.tobytes() if six.PY3 else names.tostring()
    names = [names[i:i + offset].split(b'\0', 1)[0] for i in range(0, out, name_len)]  # noqa: E501

    # Look for the IP address
    for ifname in names:
        # Only look for a matching interface name
        if not ifname.decode("utf8").startswith(iface_name):
            continue

        # Retrieve and convert addresses
        ifreq = ioctl(sck, SIOCGIFADDR, struct.pack("16s16x", ifname))
        ifaddr = struct.unpack(">I", ifreq[20:24])[0]
        ifreq = ioctl(sck, SIOCGIFNETMASK, struct.pack("16s16x", ifname))
        msk = struct.unpack(">I", ifreq[20:24])[0]

        # Get the full interface name
        ifname = plain_str(ifname)
        if ':' in ifname:
            ifname = ifname[:ifname.index(':')]
        else:
            continue

        # Check if the source address is included in the network
        if (ifaddr & msk) == ip_mask:
            sck.close()
            return (ifaddr & msk, msk, gw_str, ifname,
                    scapy.utils.ltoa(ifaddr), metric)

    sck.close()
    return
1104083
def network(ip, netmask, gateway):
    '''
    
    '''
    ret = {'name': ip,
           'result': True,
           'changes': {},
           'comment': ''}

    current_network = __salt__['drac.network_info']()
    new_network = {}

    if ip != current_network['IPv4 settings']['IP Address']:
        ret['changes'].update({'IP Address':
                              {'Old': current_network['IPv4 settings']['IP Address'],
                               'New': ip}})

    if netmask != current_network['IPv4 settings']['Subnet Mask']:
        ret['changes'].update({'Netmask':
                              {'Old': current_network['IPv4 settings']['Subnet Mask'],
                               'New': netmask}})

    if gateway != current_network['IPv4 settings']['Gateway']:
        ret['changes'].update({'Gateway':
                              {'Old': current_network['IPv4 settings']['Gateway'],
                               'New': gateway}})

    if __opts__['test']:
        ret['result'] = None
        return ret

    if __salt__['drac.set_network'](ip, netmask, gateway):
        if not ret['changes']:
            ret['comment'] = 'Network is in the desired state'

        return ret

    ret['result'] = False
    ret['comment'] = 'unable to configure network'

    return ret
418862
def getBroadcast (self, ifname):
        
        if sys.platform == 'darwin':
            return ifconfig_inet(ifname).get('broadcast')
        return self._getaddr(ifname, self.SIOCGIFBRDADDR)
400414
private int computeNetworkPrefixFromMask(IPAddress mask) {
		
		int result = 0;
		int tmp = mask.getIPAddress();
		
		while ((tmp & 0x00000001) == 0x00000001) {
			result++;
			tmp = tmp >>> 1;
		}
		
		if (tmp != 0) {
			return -1;
		}
		
		return result;
	}
1104645
function &interfaceNamed($interfaceName)
    {
        $return = NULL;
        if (isset($this->_interfaces[$interfaceName])) {
            $return =& $this->_interfaces[$interfaceName];
        }

        return $return;
    }
1289276
def _convert_netmask(mask):
    """"""
    if mask not in range(0, 33):
        raise scci.SCCIInvalidInputError(
            'Netmask value is invalid.')

    return socket.inet_ntoa(struct.pack(
        '!L', int('1' * mask + '0' * (32 - mask), 2)))
735047
function isNetworkSame(maskstr, ip1str, ip2str) {
    let mask = convToNum(maskstr);
    let ip1 = convToNum(ip1str);
    let ip2 = convToNum(ip2str);
    return (ip1&mask) == (ip2&mask);
}