List of usage examples for com.google.common.net InetAddresses coerceToInteger
public static int coerceToInteger(InetAddress ip)
From source file:org.opendaylight.genius.resourcemanager.ResourceManagerUtils.java
protected static String getLocalPoolName(String poolName) { if (localHostAddress == null) { try {// w w w .j av a 2s . co m localHostAddress = InetAddresses.coerceToInteger(InetAddress.getLocalHost()); } catch (UnknownHostException e) { LOG.error("Cannot build the local pool name: ", e); } } return poolName + "." + localHostAddress; }
From source file:io.airlift.http.server.Inet4Network.java
public Inet4Address getEndingAddress() { int start = InetAddresses.coerceToInteger(address); int length = (bits == 0) ? 0 : (1 << (32 - bits)); int end = start + length - 1; return InetAddresses.fromInteger(end); }
From source file:org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcNshHeader.java
public static Long convertIpAddressToLong(Ipv4Address ipv4Address) { return (InetAddresses.coerceToInteger(InetAddresses.forString(ipv4Address.getValue()))) & 0xFFFFFFFFL; }
From source file:com.smoketurner.dropwizard.zipkin.AbstractZipkinFactory.java
private static int toInt(final String ip) { return InetAddresses.coerceToInteger(InetAddresses.forString(ip)); }
From source file:org.opendaylight.faas.fabric.utils.IpAddressUtils.java
public static long getDefaultMask(String ipv4Address) { long ipLong = (InetAddresses.coerceToInteger(InetAddresses.forString(ipv4Address))) & 0xFFFFFFFFL; if (ipLong < 2147483647L) { // 0.0.0.0 - 127.255.255.255 return 8; }/*from w w w . j av a 2s.co m*/ if (ipLong < 3221225471L) { // 128.0.0.0 - 191.255.255.255 return 16; } if (ipLong < 3758096383L) { // 192.0.0.0 - 223.255.255.255 return 24; } return 32;// other }
From source file:io.airlift.http.server.Inet4Network.java
public static Inet4Network fromAddress(Inet4Address address, int bits) { if ((bits < 0) || (bits > 32)) { throw new IllegalArgumentException("invalid prefix size: " + bits); }//from w w w . j a v a 2 s . co m int mask = (bits == 0) ? 0 : (-1 << (32 - bits)); int ip = InetAddresses.coerceToInteger(address); if ((ip & mask) != ip) { throw new IllegalArgumentException("invalid prefix for prefix size: " + bits); } return new Inet4Network(address, bits); }
From source file:org.squiddev.cctweaks.lua.lib.socket.AddressMatcher.java
public AddressMatcher(String[] matches) { boolean active = false; for (String host : matches) { try {/* ww w . j a va 2 s. com*/ Matcher matcher = cidrPattern.matcher(host); if (matcher.matches()) { String address = matcher.group(1), prefix = matcher.group(2); int addr = InetAddresses.coerceToInteger(InetAddresses.forString(address)); int mask = 0xFFFFFFFF << (32 - Integer.parseInt(prefix)); int min = addr & mask; int max = addr | ~mask; active = true; ranges.add(new HostRange(min, max)); } else { active = true; hosts.add(host); addresses.add(InetAddress.getByName(host)); } } catch (Exception e) { Logger.error("Error adding " + host + " to blacklist/whitelist", e); } } this.active = active; }
From source file:io.airlift.http.server.Inet4Network.java
public static Inet4Network truncatedFromAddress(Inet4Address address, int bits) { int mask = (bits == 0) ? 0 : (-1 << (32 - bits)); int ip = InetAddresses.coerceToInteger(address); return fromAddress(InetAddresses.fromInteger(ip & mask), bits); }
From source file:org.opendaylight.genius.mdsalutil.actions.ActionLoadIpToSpa.java
@Override public Action buildAction(int newActionKey) { return new ActionBuilder() .setAction(//from w ww.ja va 2 s.co m new NxActionRegLoadNodesNodeTableFlowApplyActionsCaseBuilder() .setNxRegLoad(new NxRegLoadBuilder() .setDst(new DstBuilder() .setDstChoice( new DstOfArpSpaCaseBuilder().setOfArpSpa(true).build()) .setStart(0).setEnd(31).build()) .setValue(BigInteger.valueOf( InetAddresses.coerceToInteger(InetAddresses.forString(address)) & 0xffffffffL)) .build()) .build()) .setKey(new ActionKey(newActionKey)).build(); }
From source file:io.airlift.http.server.Inet4Network.java
static long addressToLong(Inet4Address address) { return InetAddresses.coerceToInteger(address) & 0xffffffffL; }