inet.ipaddr.ipv6

Class IPv6Address

    • 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
      • IPv6Address

        public IPv6Address(Address.SegmentValueProvider lowerValueProvider,
                           Address.SegmentValueProvider upperValueProvider,
                           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:
        lowerValueProvider - supplies the 2 byte lower values for each segment
        upperValueProvider - supplies the 2 byte upper values for each segment
        networkPrefixLength - the CIDR network prefix length, which can be null for no prefix
      • IPv6Address

        public IPv6Address(Address.SegmentValueProvider lowerValueProvider,
                           Address.SegmentValueProvider upperValueProvider)
        Constructs an IPv6 address or subnet.
        Parameters:
        lowerValueProvider - supplies the 2 byte lower values for each segment
        upperValueProvider - supplies the 2 byte upper values for each segment
      • IPv6Address

        public IPv6Address(Address.SegmentValueProvider lowerValueProvider,
                           Address.SegmentValueProvider upperValueProvider,
                           java.lang.CharSequence zone)
        Constructs an IPv6 address.
        Parameters:
        lowerValueProvider - supplies the 2 byte lower values for each segment
        upperValueProvider - supplies the 2 byte upper values for each segment
      • IPv6Address

        public IPv6Address(IPv6Address prefix,
                           MACAddress eui)
        Constructs an IPv6 address from a modified EUI-64 (Extended Unique Identifier) address section and an IPv6 address section network prefix. If the supplied MAC section is an 8 byte EUI-64, then it must match the required EUI-64 format of xx-xx-ff-fe-xx-xx with the ff-fe section in the middle. If the supplied section is a 6 byte MAC-48 or EUI-48, then the ff-fe pattern will be inserted. If the supplied section neither 6 nor 8 bytes, or if the 8-byte section does not have required EUI-64 format of xx-xx-ff-fe-xx-xx, AddressTypeException will be thrown. The constructor will toggle the MAC U/L (universal/local) bit as required with EUI-64. Only the first 8 bytes (4 segments) of the IPv6Address are used to construct the address.
        Parameters:
        section -
        eui -
      • IPv6Address

        public IPv6Address(IPv6AddressSection section,
                           MACAddress eui)
        Constructs an IPv6 address from a modified EUI-64 (Extended Unique Identifier) address section and an IPv6 address section network prefix. If the supplied MAC section is an 8 byte EUI-64, then it must match the required EUI-64 format of xx-xx-ff-fe-xx-xx with the ff-fe section in the middle. If the supplied section is a 6 byte MAC-48 or EUI-48, then the ff-fe pattern will be inserted. If the supplied section neither 6 nor 8 bytes, or if the 8-byte section does not have required EUI-64 format of xx-xx-ff-fe-xx-xx, AddressTypeException will be thrown. The constructor will toggle the MAC U/L (universal/local) bit as required with EUI-64. The IPv6 address section must be 8 bytes.
        Parameters:
        section -
        eui -
      • IPv6Address

        public IPv6Address(IPv6AddressSection section,
                           MACAddressSection eui)
        Constructs an IPv6 address from a modified EUI-64 (Extended Unique Identifier) address and an IPv6 address section network prefix. If the supplied address is an 8 byte EUI-64, then it must match the required EUI-64 format of xx-xx-ff-fe-xx-xx with the ff-fe section in the middle. If the supplied address is a 6 byte MAC-48 or EUI-48, then the ff-fe pattern will be inserted. The constructor will toggle the MAC U/L (universal/local) bit as required with EUI-64. The IPv6 address section must be 8 bytes.
        Parameters:
        section -
        eui -
    • Method Detail

      • getLoopback

        public static IPv6Address getLoopback()
      • getStandardLoopbackStrings

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

        public boolean isEUI64()
      • toEUI

        public MACAddress toEUI(boolean extended)
      • 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 interface AddressComponent
        Specified by:
        getLower in interface AddressSegmentSeries
        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 interface AddressComponent
        Specified by:
        getUpper in interface AddressSegmentSeries
        Specified by:
        getUpper in class IPAddress
        Returns:
      • reverseBits

        public IPv6Address reverseBits(boolean perByte)
        Description copied from class: IPAddress
        Returns a new IPAddress which has the bits reversed. If this represents a range of values that cannot be reversed, then this throws AddressTypeException. In such cases where isMultiple() is true, call iterator(), getLower(), getUpper() or some other methods to transform the address into an address representing a single value.
        Specified by:
        reverseBits in interface AddressComponent
        Specified by:
        reverseBits in interface AddressSegmentSeries
        Specified by:
        reverseBits in class IPAddress
        Parameters:
        perByte - if true, only the bits in each byte are reversed, if false, then all bits in the address are reversed
        Returns:
      • iterator

        public java.util.Iterator<IPv6Address> iterator()
        Description copied from interface: AddressComponent
        An address component can represent a single segment, address, or section, or it can represent multiple, typically a subnet or range of segment, address, or section values. Call AddressItem.isMultiple() to determine if this instance represents multiple. This method iterates through the individual elements.
        Specified by:
        iterator in interface AddressComponent
        Specified by:
        iterator in interface AddressSegmentSeries
        Specified by:
        iterator in interface java.lang.Iterable<IPv6Address>
        Specified by:
        iterator in class IPAddress
        Returns:
      • from

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

        public static IPv6Address from(byte[] bytes,
                                       java.lang.CharSequence 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 Address
        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 subnets 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 subnet but not in the provided subnet. If the address is not the same version, the default conversion will be applied, and it that fails, AddressTypeException will be thrown.
        Specified by:
        subtract in class IPAddress
        Returns:
        the difference
      • adjustPrefixLength

        public IPv6Address adjustPrefixLength(int adjustment)
        Description copied from interface: AddressSegmentSeries
        Increases or decreases prefix length by the given increment. When prefix length is increased, the bits moved within the prefix become zero. When the prefix is extended beyond the segment series boundary, it is removed.
        Specified by:
        adjustPrefixLength in interface AddressSegmentSeries
        Specified by:
        adjustPrefixLength in class IPAddress
        Returns:
      • setPrefixLength

        public IPv6Address setPrefixLength(int prefixLength)
        Description copied from interface: AddressSegmentSeries
        Sets the prefix length. When the series already had a prefix, and the prefix length is increased, the bits moved within the prefix are zero. When the prefix is extended beyond the segment series boundary, it is removed.
        Specified by:
        setPrefixLength in interface AddressSegmentSeries
        Specified by:
        setPrefixLength in class IPAddress
        Returns:
      • mask

        public IPv6Address mask(IPAddress mask)
                         throws AddressTypeException
        Description copied from class: IPAddress
        Applies the given mask to all addresses represented by this IPAddress. Any existing prefix is removed as the mask is applied to all individual addresses. If this represents multiple addresses, and applying the mask to all addresses creates a set of addresses that cannot be represented as a contiguous range within each segment, then AddressTypeException is thrown.
        Specified by:
        mask in class IPAddress
        Throws:
        AddressTypeException
      • maskNetwork

        public IPv6Address maskNetwork(IPAddress mask,
                                       int networkPrefixLength)
                                throws AddressTypeException
        Description copied from class: IPAddress
        Applies the given mask up until the given prefix length to all addresses represented by this IPAddress. Any existing prefix length is removed as the mask is applied to all individual addresses. If networkPrefixLength is non-null, it is applied after the mask has been applied. If this represents multiple addresses, and applying the mask to all addresses creates a set of addresses that cannot be represented as a contiguous range within each segment, then AddressTypeException is thrown.
        Specified by:
        maskNetwork in class IPAddress
        Throws:
        AddressTypeException
      • bitwiseOrNetwork

        public IPv6Address bitwiseOrNetwork(IPAddress mask,
                                            int networkPrefixLength)
                                     throws AddressTypeException
        Description copied from class: IPAddress
        Does the bitwise disjunction with this address. Useful when subnetting. Any existing prefix length is dropped for the new prefix length and the mask is applied up to the end the new prefix length.
        Specified by:
        bitwiseOrNetwork in class IPAddress
        networkPrefixLength - the new prefix length for the address
        Returns:
        Throws:
        AddressTypeException
      • getNetworkSection

        public IPv6AddressSection getNetworkSection(int networkPrefixLength)
        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. 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
        Returns:
      • 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()
        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
        Specified by:
        toCanonicalString in interface AddressSegmentSeries
        Overrides:
        toCanonicalString in class Address
        Returns:
      • 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()
        The normalized string returned by this method is consistent with java.net.Inet6address. IPs are not compressed nor mixed in this representation.
        Specified by:
        toNormalizedString in interface AddressComponent
        Overrides:
        toNormalizedString in class Address
        Returns:
      • 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
      • toBase85String

        public java.lang.String toBase85String()
        The base 85 string is described by RFC 1924
        Returns:
      • 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 with0xPrefix)
        Description copied from class: Address
        Writes this address as a single hexadecimal value with always the exact same number of characters, with or without a preceding 0x prefix. If this section represents a range of values outside of the network prefix length, then this is printed as a range of two hex values.
        Specified by:
        toHexString in interface AddressComponent
        Overrides:
        toHexString in class Address
      • toBinaryString

        public java.lang.String toBinaryString()
        Description copied from class: IPAddress
        Writes this address as a single binary value with always the exact same number of characters If this section represents a range of values outside of the network prefix length, then this is printed as a range of two hex values.
        Overrides:
        toBinaryString in class IPAddress
      • toOctalString

        public java.lang.String toOctalString(boolean with0Prefix)
        Description copied from class: IPAddress
        Writes this address as a single octal value with always the exact same number of characters, with or without a preceding 0 prefix. If this section represents a range of values outside of the network prefix length, then this is printed as a range of two hex values.
        Overrides:
        toOctalString in class IPAddress
      • toPrefixLengthString

        public java.lang.String toPrefixLengthString()
        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:
        toPrefixLengthString 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(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: