inet.ipaddr.ipv6

Class IPv6Address

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<IPAddress>, java.lang.Iterable<IPv6Address>


    public class IPv6Address
    extends IPAddress
    implements java.lang.Iterable<IPv6Address>
    An IPv6 address, or a subnet of multiple IPv6 addresses.
    See Also:
    Serialized Form
    Core
    • Constructor Detail

      • IPv6Address

        public IPv6Address(IPv6AddressSegment[] segments)
        Constructs an IPv6 address or subnet.
        Parameters:
        segments - the address segments
      • IPv6Address

        public IPv6Address(IPv6AddressSegment[] segments,
                           java.lang.Integer networkPrefixLength)
        Constructs an IPv6 address or a set of addresses. When networkPrefixLength is non-null, this object represents a network prefix or the set of addresses with the same network prefix (a network or subnet, in other words).
        Parameters:
        segments - the address segments
        networkPrefixLength -
      • IPv6Address

        public IPv6Address(IPv6AddressSegment[] segments,
                           java.lang.CharSequence zone)
        Constructs an IPv6 address or a set of addresses.
        Parameters:
        segments - the address segments
        zone - the zone
      • IPv6Address

        public IPv6Address(IPv6AddressSection section,
                           java.lang.CharSequence zone)
      • IPv6Address

        public IPv6Address(byte[] bytes,
                           java.lang.CharSequence zone)
        Constructs an IPv6 address.
        Parameters:
        bytes - must be a 16 byte IPv6 address
      • IPv6Address

        public IPv6Address(byte[] bytes)
        Constructs an IPv6 address.
        Parameters:
        bytes - must be a 16 byte IPv6 address
      • IPv6Address

        public IPv6Address(byte[] bytes,
                           java.lang.Integer networkPrefixLength)
        Constructs an IPv6 address or subnet. When networkPrefixLength is non-null, this object represents a network prefix or the set of addresses with the same network prefix (a network or subnet, in other words).
        Parameters:
        bytes - must be a 16 byte IPv6 address
        networkPrefixLength - the CIDR prefix, which can be null for no prefix length
        Throws:
        java.lang.IllegalArgumentException - if bytes is not length 16
    • Method Detail

      • getLoopback

        public static IPv6Address getLoopback()
      • getStandardLoopbackStrings

        public static java.lang.String[] getStandardLoopbackStrings()
      • getLower

        public IPv6Address getLower()
        Description copied from class: IPAddress
        If this represents an address with ranging values, returns an address representing the lower values of the range. If this represents an address with a single value in each segment, returns this.
        Specified by:
        getLower in class IPAddress
        Returns:
      • getUpper

        public IPv6Address getUpper()
        Description copied from class: IPAddress
        If this represents an address with ranging values, returns an address representing the upper values of the range If this represents an address with a single value in each segment, returns this.
        Specified by:
        getUpper in class IPAddress
        Returns:
      • getAddresses

        public java.lang.Iterable<IPv6Address> getAddresses()
        Specified by:
        getAddresses in class IPAddress
        Returns:
        an object to iterate over the individual addresses represented by this object.
      • from

        public static IPv6Address from(byte[] bytes,
                                       byte[] bytes2,
                                       java.lang.Integer prefix,
                                       java.lang.String zone)
      • from

        public static IPv6Address from(byte[] bytes,
                                       java.lang.String zone)
      • toIPv6

        public IPv6Address toIPv6()
        Overrides:
        toIPv6 in class IPAddress
        Returns:
        If this address is IPv6, or can be converted to IPv6, returns that IPv6Address. Otherwise, returns null.
      • isIPv4Convertible

        public boolean isIPv4Convertible()
        Determines whether this address can be converted to IPv4. Override this method to convert in your own way, or call setAddressConverter with your own converter object. The default behaviour is to use isIPv4Mapped() You should also override toIPv4() to match the conversion.
        Specified by:
        isIPv4Convertible in class IPAddress
        Returns:
      • isIPv6Convertible

        public boolean isIPv6Convertible()
        Description copied from class: IPAddress
        Determines whether an address can be converted to IPv6, if not IPv6 already. Override this method to convert in your own way, or call setAddressConverter with your own converter object. You should also override IPAddress.toIPv6() to match the conversion. This method returns true for all IPv6 addresses.
        Specified by:
        isIPv6Convertible in class IPAddress
        Returns:
      • toMappedIPv4Segments

        public IPv4AddressSection toMappedIPv4Segments()
        ::ffff:x:x/96 indicates IPv6 address mapped to IPv4
      • get6to4IPv4Address

        public IPv4Address get6to4IPv4Address()
        Returns the second and third bytes as an IPv4Address. This can be used for IPv4 or for IPv6 6to4 addresses convertible to IPv4.
        Returns:
        the address
      • getEmbeddedIPv4Address

        public IPv4Address getEmbeddedIPv4Address()
        Returns the embedded IPv4Address in the lowest (least-significant) two segments. This is used by IPv4-mapped, IPv4-compatible, ISATAP addresses and 6over4 addresses
        Returns:
        the embedded IPv4Address
      • getEmbeddedIPv4Address

        public IPv4Address getEmbeddedIPv4Address(int byteIndex)
        Produces an IPv4 address from any sequence of 4 bytes in this IPv6 address.
        Parameters:
        byteIndex - the byte index to start
        Returns:
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is less than zero or bigger than 7
      • isLinkLocal

        public boolean isLinkLocal()
        Specified by:
        isLinkLocal in class IPAddress
        See Also:
        InetAddress.isLinkLocalAddress()
      • isSiteLocal

        public boolean isSiteLocal()
        Specified by:
        isSiteLocal in class IPAddress
        See Also:
        InetAddress.isSiteLocalAddress()
      • isUniqueLocal

        public boolean isUniqueLocal()
      • isIPv4Mapped

        public boolean isIPv4Mapped()
        Whether the address is IPv4-mapped ::ffff:x:x/96 indicates IPv6 address mapped to IPv4
      • isIPv4Compatible

        public boolean isIPv4Compatible()
        Whether the address is IPv4-compatible
        See Also:
        Inet6Address.isIPv4CompatibleAddress()
      • is6To4

        public boolean is6To4()
        Whether the address is IPv6 to IPv4 relay
        See Also:
        get6to4IPv4Address()
      • is6Over4

        public boolean is6Over4()
        Whether the address is 6over4
      • isTeredo

        public boolean isTeredo()
        Whether the address is Teredo
      • isIsatap

        public boolean isIsatap()
        Whether the address is ISATAP
      • isIPv4Translatable

        public boolean isIPv4Translatable()
        Returns:
        Whether the address is IPv4 translatable as in rfc 2765
      • isWellKnownIPv4Translatable

        public boolean isWellKnownIPv4Translatable()
        Whether the address has the well-known prefix for IPv4 translatable addresses as in rfc 6052 and 6144
        Returns:
      • isMulticast

        public boolean isMulticast()
        Specified by:
        isMulticast in class IPAddress
        See Also:
        InetAddress.isMulticastAddress()
      • isLoopback

        public boolean isLoopback()
        Specified by:
        isLoopback in class IPAddress
        See Also:
        InetAddress.isLoopbackAddress()
      • subtract

        public IPv6Address[] subtract(IPAddress other)
        Description copied from class: IPAddress
        Subtract the give subnet from this subnet, returning an array of sections for the result (the subnets will not be contiguous so an array is required). Computes the subnet difference, the set of addresses in this address section but not in the provided section.
        Specified by:
        subtract in class IPAddress
        Returns:
        the difference
      • toSubnet

        public IPv6Address toSubnet(int networkPrefixLength)
                             throws IPAddressTypeException
        Description copied from class: IPAddress
        Creates a subnet address using the given CIDR prefix bits. Since no mask is applied to all of the addresses represented (as with the other toSubnet methods), any existing prefix or range remains the same before applying the additional prefix.
        Specified by:
        toSubnet in class IPAddress
        Throws:
        IPAddressTypeException
      • toSubnet

        public IPv6Address toSubnet(IPAddress mask,
                                    java.lang.Integer networkPrefixLength)
                             throws IPAddressTypeException
        Creates a subnet address using the given mask. If networkPrefixLength is non-null, applies the prefix length as well. The mask can be a subnet itself, in which case the lowest value of the mask's range is used.
        Specified by:
        toSubnet in class IPAddress
        Throws:
        IPAddressTypeException
      • getNetworkSection

        public IPv6AddressSection getNetworkSection(int networkPrefixLength,
                                                    boolean withPrefixLength)
        Description copied from class: IPAddress
        Generates the network section of the address. The returned section will have only as many segments as needed to hold the network as indicated by networkPrefixLength. If withPrefixLength is true, it will have networkPrefixLength as its associated prefix length, unless this address already has a smaller prefix length, in which case the existing prefix length is retained.
        Specified by:
        getNetworkSection in class IPAddress
        withPrefixLength - whether the resulting section will have networkPrefixLength as the associated prefix length or not
        Returns:
      • getNetworkSection

        public IPv6AddressSection getNetworkSection()
        Description copied from class: IPAddress
        Generates the network section of the address if the address is a CIDR prefix, otherwise it generates the entire address as a prefixed address with prefix matching the address bit length.
        Specified by:
        getNetworkSection in class IPAddress
        Returns:
      • getHostSection

        public IPv6AddressSection getHostSection(int networkPrefixLength)
        Description copied from class: IPAddress
        Generates the host section of the address. The returned section will have only as many segments as needed to hold the host as indicated by cidrBits.
        Specified by:
        getHostSection in class IPAddress
        Returns:
      • getHostSection

        public IPv6AddressSection getHostSection()
        Description copied from class: IPAddress
        Generates the host section of the address. The returned section will have only as many segments as needed as determined by the existing CIDR prefix length. If there is no CIDR prefix length, the host section will have 0 segments.
        Specified by:
        getHostSection in class IPAddress
        Returns:
      • hasZone

        public boolean hasZone()
      • getZone

        public java.lang.String getZone()
      • contains

        public boolean contains(IPAddress other)
        Overrides:
        contains in class IPAddress
        Parameters:
        other -
        Returns:
        whether this subnet contains the given address
      • toMixedString

        public java.lang.String toMixedString()
      • toCanonicalString

        public java.lang.String toCanonicalString()
        Description copied from class: IPAddress
        This produces a canonical string. RFC 5952 describes canonical representations. http://en.wikipedia.org/wiki/IPv6_address#Recommended_representation_as_text http://tools.ietf.org/html/rfc5952 Each address has a unique canonical string, not counting the prefix, which can give two equal addresses different strings.
        Overrides:
        toCanonicalString in class IPAddress
      • toFullString

        public java.lang.String toFullString()
        Description copied from class: IPAddress
        This produces a string with no compressed segments and all segments of full length, which is 4 characters for IPv6 segments and 3 characters for IPv4 segments. Each address has a unique full string, not counting CIDR the prefix, which can give two equal addresses different strings.
        Overrides:
        toFullString in class IPAddress
      • toNormalizedString

        public java.lang.String toNormalizedString()
        Description copied from class: IPAddress
        The normalized string returned by this method is consistent with java.net.Inet4Address and java.net.Inet6Address. IPs are not compressed nor mixed in this representation. The string returned by this method is unique for each address, not counting CIDR the prefix, which can give two equal addresses different strings.
        Overrides:
        toNormalizedString in class IPAddress
      • toCompressedString

        public java.lang.String toCompressedString()
        Description copied from class: IPAddress
        This produces the shortest valid string for the address. Each address has a unique compressed string, not counting the prefix, which can give two equal addresses different strings. For subnets the string will not have wildcards in host segments (there will be zeros instead), only in network segments.
        Overrides:
        toCompressedString in class IPAddress
      • toSubnetString

        public java.lang.String toSubnetString()
        Description copied from class: IPAddress
        Produces a consistent subnet string that looks like 1.2.*.* or 1:2::/16 In the case of IPv4, this means that wildcards are used instead of a network prefix when a network prefix has been supplied. In the case of IPv6, when a network prefix has been supplied, the prefix will be shown and the host section will be compressed with ::.
        Overrides:
        toSubnetString in class IPAddress
      • toNormalizedWildcardString

        public java.lang.String toNormalizedWildcardString()
        Description copied from class: IPAddress
        This produces a string similar to the normalized string but avoids the CIDR prefix. CIDR addresses will be shown with wildcards and ranges instead of using the CIDR prefix notation.
        Overrides:
        toNormalizedWildcardString in class IPAddress
      • toCanonicalWildcardString

        public java.lang.String toCanonicalWildcardString()
        Description copied from class: IPAddress
        This produces a string similar to the canonical string but avoids the CIDR prefix. Addresses with a network prefix length will be shown with wildcards and ranges instead of using the CIDR prefix length notation. IPv6 addresses will be compressed according to the canonical representation.
        Overrides:
        toCanonicalWildcardString in class IPAddress
      • toCompressedWildcardString

        public java.lang.String toCompressedWildcardString()
        Description copied from class: IPAddress
        This is similar to toNormalizedWildcardString, avoiding the CIDR prefix, but with compression as well.
        Overrides:
        toCompressedWildcardString in class IPAddress
      • toSQLWildcardString

        public java.lang.String toSQLWildcardString()
        Description copied from class: IPAddress
        This is the same as the string from toNormalizedWildcardString except that it uses IPAddress.SEGMENT_SQL_WILDCARD instead of IPAddress.SEGMENT_WILDCARD and also uses IPAddress.SEGMENT_SQL_SINGLE_WILDCARD
        Overrides:
        toSQLWildcardString in class IPAddress
      • toHexString

        public java.lang.String toHexString(boolean withPrefix)
        Description copied from class: IPAddress
        Writes this address as hexadecimal, with or without a preceding 0x prefix
        Overrides:
        toHexString in class IPAddress
      • toNetworkPrefixLengthString

        public java.lang.String toNetworkPrefixLengthString()
        Description copied from class: IPAddress
        Returns a string with a CIDR network prefix length if this address has a network prefix length. For IPv6, the host section will be compressed with ::, for IPv4 the host section will be zeros.
        Overrides:
        toNetworkPrefixLengthString in class IPAddress
        Returns:
      • toConvertedString

        public java.lang.String toConvertedString()
        Description copied from class: IPAddress
        Returns a mixed string if it represents a convertible IPv4 address, returns the normalized string otherwise.
        Overrides:
        toConvertedString in class IPAddress
        Returns:
      • toNormalizedString

        public java.lang.String toNormalizedString(IPAddressSection.StringOptions params)
        Description copied from class: IPAddress
        Constructs a string representing this address according to the given parameters
        Overrides:
        toNormalizedString in class IPAddress
        Parameters:
        params - the parameters for the address string
      • toNormalizedString

        public java.lang.String toNormalizedString(boolean keepMixed,
                                                   IPv6AddressSection.IPv6StringOptions params)
        Constructs a string representing this address according to the given parameters
        Parameters:
        keepMixed - if this address was constructed from a string with mixed representation (a:b:c:d:e:f:1.2.3.4), whether to keep it that way (ignored if makeMixed is true in the params argument)
        params - the parameters for the address string
      • toUNCHostName

        public java.lang.String toUNCHostName()
        Description copied from class: IPAddress
        Generates the Microsoft UNC path component for this address
        Specified by:
        toUNCHostName in class IPAddress
        Returns:
      • toReverseDNSLookupString

        public java.lang.String toReverseDNSLookupString()
        Description copied from class: IPAddress
        Generates the reverse DNS lookup string For 8.255.4.4 it is 4.4.255.8.in-addr.arpa For 2001:db8::567:89ab it is b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa
        Specified by:
        toReverseDNSLookupString in class IPAddress
        Returns: