/** * Check if this IP address is self-assigned. * * @return true if this address is self-assigned */ public boolean isSelfAssigned() { return isIp4() && octets[0] == (byte) 169 && octets[1] == (byte) 254; }
/** * Tests whether the IP version of this prefix is IPv4. * * @return true if the IP version of this prefix is IPv4, otherwise false. */ public boolean isIp4() { return address.isIp4(); }
/** * The size in bytes of a serialized address. * * @return the number of bytes when serialized */ public int getByteSize() { int size = 4; size += addr.isIp4() ? 4 : 16; return size; }
/** * The size in bytes of a serialized address. * * @return the number of bytes when serialized */ public int getByteSize() { int size = 4; size += addr.isIp4() ? PIM.ADDRESS_FAMILY_IP4 : PIM.ADDRESS_FAMILY_IP6; return size; }
/** * PIM Encoded Source Address. * * @param addr IPv4 or IPv6 */ public void setAddr(IpAddress addr) { this.addr = addr; if (this.addr.isIp4()) { this.family = PIM.ADDRESS_FAMILY_IP4; } else { this.family = PIM.ADDRESS_FAMILY_IP6; } }
/** * The size in bytes of a serialized address. * * @return the number of bytes when serialized */ public int getByteSize() { int size = 2; if (addr != null) { size += addr.isIp4() ? 4 : 16; } else { size += 4; } return size; }
/** * Initializes LISP locator's IPv4 address. * * @param address IP address */ public LispIpv4Address(IpAddress address) { super(address, AddressFamilyIdentifierEnum.IP4); checkArgument(address.isIp4()); }
/** * PIM Encoded Source Address. * * @param addr IPv4 or IPv6 */ public PIMAddrUnicast(String addr) { this.addr = IpAddress.valueOf(addr); if (this.addr.isIp4()) { this.family = PIM.ADDRESS_FAMILY_IP4; } else { this.family = PIM.ADDRESS_FAMILY_IP6; } this.encType = 0; }
/** * Gets the {@link Ip4Address} view of the IP address. * * @return the {@link Ip4Address} view of the IP address if it is IPv4, * otherwise null */ public Ip4Address getIp4Address() { if (!isIp4()) { return null; } // Return this object itself if it is already instance of Ip4Address if (this instanceof Ip4Address) { return (Ip4Address) this; } return Ip4Address.valueOf(octets); }
public byte[] serialize() { int len = addr.isIp4() ? ENC_SOURCE_IPV4_BYTE_LENGTH : ENC_SOURCE_IPV6_BYTE_LENGTH; final byte[] data = new byte[len]; final ByteBuffer bb = ByteBuffer.wrap(data); bb.put(this.family); bb.put(this.encType); // Todo: technically we should be setting the B and Z bits, but we'll never use them. byte mask = 0x0; if (this.sBit) { this.reserved |= 0x4; } if (this.wBit) { this.reserved |= 0x2; } if (this.rBit) { this.reserved |= 0x1; } bb.put(reserved); bb.put(this.masklen); bb.put(this.addr.toOctets()); return data; }
/** * PIM Encoded Source Address. * * @param spfx IPv4 or IPv6 address prefix */ public void setAddr(IpPrefix spfx) { this.addr = spfx.address(); this.masklen = (byte) spfx.prefixLength(); this.family = (byte) ((this.addr.isIp4()) ? PIM.ADDRESS_FAMILY_IP4 : PIM.ADDRESS_FAMILY_IP6); }
/** * Set the encoded source address. * * @param pfx address prefix */ public void setAddr(IpPrefix pfx) { this.addr = pfx.address(); this.masklen = (byte) pfx.prefixLength(); this.family = (byte) ((this.addr.isIp4()) ? PIM.ADDRESS_FAMILY_IP4 : PIM.ADDRESS_FAMILY_IP6); }
@Override public final void setChannel(Channel channel) { this.channel = channel; final SocketAddress address = channel.getRemoteAddress(); if (address instanceof InetSocketAddress) { final InetSocketAddress inetAddress = (InetSocketAddress) address; final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress()); if (ipAddress.isIp4()) { channelId = ipAddress.toString() + ':' + inetAddress.getPort(); } else { channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort(); } } };
@Override public final void setChannel(Channel channel) { this.channel = channel; final SocketAddress address = channel.getRemoteAddress(); if (address instanceof InetSocketAddress) { final InetSocketAddress inetAddress = (InetSocketAddress) address; final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress()); if (ipAddress.isIp4()) { channelId = ipAddress.toString() + ':' + inetAddress.getPort(); } else { channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort(); } } };
@Override public final void setChannel(Channel channel) { this.channel = channel; final SocketAddress address = channel.getRemoteAddress(); if (address instanceof InetSocketAddress) { final InetSocketAddress inetAddress = (InetSocketAddress) address; final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress()); if (ipAddress.isIp4()) { channelId = ipAddress.toString() + ':' + inetAddress.getPort(); } else { channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort(); } } }
@Override public boolean isIpAddressLocal(IpAddress ipAddress) { if (ipAddress.isIp4()) { return localPrefixTable4.getValuesForKeysPrefixing( createBinaryString( IpPrefix.valueOf(ipAddress, Ip4Address.BIT_LENGTH))) .iterator().hasNext(); } else { return localPrefixTable6.getValuesForKeysPrefixing( createBinaryString( IpPrefix.valueOf(ipAddress, Ip6Address.BIT_LENGTH))) .iterator().hasNext(); } }
/** * Check if this IP address is a multicast address. * * @return true if this address is a multicast address */ public boolean isMulticast() { return isIp4() ? Ip4Prefix.IPV4_MULTICAST_PREFIX.contains(this.getIp4Address()) : Ip6Prefix.IPV6_MULTICAST_PREFIX.contains(this.getIp6Address()); }
/** * Check if this IP address is a link-local address. * * @return true if this address is a link-local address */ public boolean isLinkLocal() { return isIp4() ? Ip4Prefix.IPV4_LINK_LOCAL_PREFIX.contains(this.getIp4Address()) : Ip6Prefix.IPV6_LINK_LOCAL_PREFIX.contains(this.getIp6Address()); }
/** * Generates an IP prefix. * * @return the IP prefix of the IP address */ public IpPrefix toIpPrefix() { if (isIp4()) { return IpPrefix.valueOf(new IpAddress(Version.INET, octets), Ip4Address.BIT_LENGTH); } else { return IpPrefix.valueOf(new IpAddress(Version.INET6, octets), Ip6Address.BIT_LENGTH); } }
@Override public void writeTo(ByteBuf byteBuf, LispIpAddress address) throws LispWriterException { if (address.getAddress().isIp4()) { new Ipv4AddressWriter().writeTo(byteBuf, (LispIpv4Address) address); } if (address.getAddress().isIp6()) { new Ipv6AddressWriter().writeTo(byteBuf, (LispIpv6Address) address); } } }