inet.ipaddr

Interface IPAddressSegmentSeries

    • Method Detail

      • getIPVersion

        IPAddress.IPVersion getIPVersion()
        Returns the version of this segment series
        Returns:
      • getNetworkPrefixLength

        java.lang.Integer getNetworkPrefixLength()
        Returns the CIDR network prefix length of the series, or null if the series has no associated prefix length.

        Equivalent to AddressDivisionSeries.getPrefixLength(), which is the more general concept of set of address series that share the same set of leading bits. For IP addresses and sections the prefix length and the CIDR network prefix length are the same thing.

        For IP addresses and sections each individual segment has an associated prefix length which is determine by the network prefix length. The segment prefix lengths follow the pattern: null, null, ...., null, x, 0, 0, ..., 0

        For instance, an IPv4 address 1.2.3.4/16 has the network prefix length 16. The segment prefix lengths are [null, 8, 0, 0] The segment prefix lengths of 1.2.3.4/22 are [null, null, 6, 0]

        Returns:
      • assignMinPrefixForBlock

        IPAddressSegmentSeries assignMinPrefixForBlock()
        Returns the equivalent address series with the smallest CIDR prefix possible (largest network), such that the range of values of this address includes the subnet block for that prefix.
        Returns:
        See Also:
        toPrefixBlock(), assignPrefixForSingleBlock()
      • assignPrefixForSingleBlock

        IPAddressSegmentSeries assignPrefixForSingleBlock()
        Returns the equivalent CIDR address series with a prefix length for which the subnet block for that prefix matches the range of values in this series. In short, the returned series is a single block of address segment series. Another way of looking at it: if the range matches the range associated with some prefix length, then it returns the address series with that prefix length.

        If no such prefix length exists, returns null.

        If this address represents just a single address, "this" is returned.

        The methods assignMinPrefixForBlock(), assignPrefixForSingleBlock() can be compared as follows.

        assignMinPrefixForBlock() finds the smallest prefix length possible for this subnet and returns that subnet.
        assignPrefixForSingleBlock() finds the smallest prefix length possible for this subnet that results in just a single prefix and returns that subnet.

        For example, given the address 1-2.2.3.* /16
        assignMinPrefixForBlock() returns 1-2.2.3.* /24 if the prefix configuration is not ALL_PREFIXES_ARE_SUBNETS, otherwise 1-2.2.*.* /16, in order to return the subnet with the smallest prefix length
        assignPrefixForSingleBlock() returns null because any prefix length will end up with at least two prefixes due to the first segment spanning two values: 1-2.

        For another example, for the address 1.2.*.* /16 or the address 1.2.*.* both methods return 1.2.*.* /16.

        Returns:
        See Also:
        toPrefixBlock(), assignMinPrefixForBlock()
      • toPrefixBlock

        IPAddressSegmentSeries toPrefixBlock()
        If this series has a prefix length, returns the subnet block for that prefix. If this series has no prefix length, this series is returned.
        Specified by:
        toPrefixBlock in interface AddressSegmentSeries
        Returns:
        the subnet block for the prefix length
      • toPrefixBlock

        IPAddressSegmentSeries toPrefixBlock(int networkPrefixLength)
                                      throws PrefixLenException
        Returns the segment series of the same length that spans all hosts. The network prefix length will be the one provided, and the network values will match the same of this series.
        Parameters:
        networkPrefixLength -
        Returns:
        Throws:
        PrefixLenException
      • getHostSection

        IPAddressSection getHostSection()
        Returns the host section of the series. The returned section will have only as many segments as needed as determined by the existing CIDR network prefix length. If this series has no CIDR prefix length, the returned host section will be the full section associated with a prefix length of 0.
        Returns:
      • getHostSection

        IPAddressSection getHostSection(int networkPrefixLength)
        Returns the host section of the address as indicated by the network prefix length provided. The returned section will have only as many segments as needed to hold the host as indicated by the provided network prefix length.
        Parameters:
        networkPrefixLength -
        Returns:
      • getNetworkSection

        IPAddressSection getNetworkSection()
        Returns the network section of the series if the series has a CIDR network prefix length, otherwise it returns the entire series as a prefixed series with prefix matching the address bit length.
        Returns:
      • getNetworkSection

        IPAddressSection getNetworkSection(int networkPrefixLength)
        Returns the network section of the series. The returned section will have only as many segments as needed 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.
        Parameters:
        networkPrefixLength -
        Returns:
      • getNetworkSection

        IPAddressSection getNetworkSection(int networkPrefixLength,
                                           boolean withPrefixLength)
        Returns the network section of the series. The returned section will have only as many segments as needed as indicated by networkPrefixLength. If withPrefixLength is true, it will have networkPrefixLength as its associated prefix length, unless this series already has a smaller prefix length, in which case the existing prefix length is retained.
        Parameters:
        networkPrefixLength -
        withPrefixLength - whether the resulting section will have networkPrefixLength as the associated prefix length or not
        Returns:
      • toFullString

        java.lang.String toFullString()
        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.
      • toPrefixLengthString

        java.lang.String toPrefixLengthString()
        Returns a string with a CIDR prefix length if this section has a network prefix length. For IPv6, the host section will be compressed with ::, for IPv4 the host section will be zeros.
        Returns:
      • toSubnetString

        java.lang.String toSubnetString()
        Produces a consistent subnet string. In the case of IPv4, this means that wildcards are used instead of a network prefix. In the case of IPv6, a prefix will be used and the host section will be compressed with ::.
      • toNormalizedWildcardString

        java.lang.String toNormalizedWildcardString()
        This produces a string similar to the normalized string and avoids the CIDR prefix. CIDR addresses will be shown with wildcards and ranges instead of using the CIDR prefix notation.
      • toCanonicalWildcardString

        java.lang.String toCanonicalWildcardString()
        This produces a string similar to the canonical string and 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.
      • toCompressedWildcardString

        java.lang.String toCompressedWildcardString()
        This is similar to toNormalizedWildcardString, avoiding the CIDR prefix, but with compression as well.
      • toReverseDNSLookupString

        java.lang.String toReverseDNSLookupString()
        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
        Returns:
        Throws:
        IncompatibleAddressException - if this address is a subnet
      • toBinaryString

        java.lang.String toBinaryString()
        Writes this IP address segment series 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.
      • toOctalString

        java.lang.String toOctalString(boolean with0Prefix)
        Writes this IP address segment series 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.
      • toNormalizedString

        java.lang.String toNormalizedString(IPAddressSection.IPStringOptions stringOptions)
        Creates a customized string from this series.
        Parameters:
        stringOptions -
        Returns:
      • getNonZeroHostCount

        java.math.BigInteger getNonZeroHostCount()
        Gets the count of single value series that this series may represent. If excludeZeroHosts is true, the count excludes series whose host is zero. If this address series has no range of values, then there is only one such address. If this has no CIDR network prefix length, then it is equivalent to AddressItem.getCount().
        Returns:
      • getLowerNonZeroHost

        IPAddressSegmentSeries getLowerNonZeroHost()
        Similar to getLower(), but will not return a series that has a prefix length and whose host value is zero. If this series has no prefix length, returns the same series as getLower().
        Returns:
        the lowest IP address series whose host is non-zero, or null if no such address section exists.
      • segmentsNonZeroHostIterator

        java.util.Iterator<? extends IPAddressSegment[]> segmentsNonZeroHostIterator()
      • increment

        IPAddressSegmentSeries increment(long increment)
        Description copied from interface: AddressSegmentSeries
        Returns the series from the subnet that is the given increment upwards into the subnet range, or if the given increment is negative the given increment downwards into the subnet range, or if this is just an individual series, it simply adds the increment to this. If the increment is 0, then this series is returned.

        If the subnet has multiple values and the increment exceeds the subnet size, then the amount by which is exceeds the size is added to the upper series of the range (the final iterator value) or is subtracted from the lower series of the range (the first iterator value) if negative.

        If the subnet is just a single address values, the series is simply incremented by the given value, positive or negative.

        If a subnet has multiple values, a positive increment value is equivalent to the same number of values from the iterator. For instance, a increment of 1 is value 1 from the iterator, an increment of 2 is the second value from the iterator, and so on. A negative increment is equivalent to the same number of values preceding the upper bound of the iterator. For instance, an increment of -1 is the last value from the iterator, and increment of -2 is the second last value, and so on.

        Therefore, to get the series just above the highest series of the subnet, use an increment of size:count > 1 ? count + 1 : 1 where count is the subnet size. To get the series just below the lowest series of the subnet, use an increment of size:-(count > 1 ? count + 1 : 1) where count is the subnet size.

        Specified by:
        increment in interface AddressSegmentSeries
        Returns:
      • toZeroHost

        IPAddressSegmentSeries toZeroHost(int prefixLength)
        Produces the series with host values of 0 for the given prefix length.

        If this series has the same prefix length, then the resulting series will too, otherwise the resulting series will have no prefix length.

        This is nearly equivalent to doing the mask (bitwise conjunction) of this address series with the network mask for the given prefix length, but without the possibility of IncompatibleAddressException that can occur when applying a mask to a range of values. Instead, in this case, if the resulting series has a range of values, then the resulting series range boundaries will have host values of 0, but not necessarily the intervening values.

        For instance, you can get the network address for a subnet of prefix length 16 as follows: String addrStr = "1.2.3.4"; IPAddress address = new IPAddressString(addrStr).getAddress(); IPAddress networkAddress = address.toZeroHost(16); //1.2.0.0

        Parameters:
        prefixLength -
        Returns:
      • includesZeroHost

        boolean includesZeroHost()
        Returns whether the series has a host of zero. If the series has no prefix length, or the prefix length matches the bit count, then returns false. Otherwise, it checks whether all bits past the prefix are zero.
        Returns:
      • includesZeroHost

        boolean includesZeroHost(int prefixLength)
        Returns whether all bits past the given prefix length are zero.
        Returns:
      • toMaxHost

        IPAddressSegmentSeries toMaxHost(int prefixLength)
        Produces the series with host values of all one bits for the given prefix length.

        If this series has the same prefix length, then the resulting series will too, otherwise the resulting series will have no prefix length.

        This is nearly equivalent to doing the bitwise or (bitwise disjunction) of this address series with the network mask for the given prefix length, but without the possibility of IncompatibleAddressException that can occur when applying a mask to a range of values. Instead, in this case, if the resulting series has a range of values, then the resulting series range boundaries will have host values of all ones, but not necessarily the intervening values.

        For instance, you can get the broadcast address for a subnet of prefix length 16 as follows: String addrStr = "1.2.3.4"; IPAddress address = new IPAddressString(addrStr).getAddress(); IPAddress broadcastAddress = address.toMaxHost(16); //1.2.255.255

        Parameters:
        prefixLength -
        Returns:
      • includesMaxHost

        boolean includesMaxHost()
        Returns whether the series has a host of all ones. If the series has no prefix length, or the prefix length matches the bit count, then returns false. Otherwise, it checks whether all bits past the prefix are ones.
        Returns:
      • includesMaxHost

        boolean includesMaxHost(int prefixLength)
        Returns whether all bits past the given prefix length are all ones.
        Returns:
      • reverseBits

        IPAddressSegmentSeries reverseBits(boolean perByte)
        Returns a new series which has the bits reversed.

        If this has an associated prefix length, then the prefix length is dropped in the reversed series.

        If this represents a range of values that cannot be reversed, because reversing the range results in a set of addresses that cannot be described by a range, then this throws IncompatibleAddressException. In such cases you can call iterator(), getLower(), getUpper() or some other method to transform the address into an address representing a single value before reversing.

        Specified by:
        reverseBits in interface AddressComponent
        Specified by:
        reverseBits in interface AddressSegmentSeries
        Parameters:
        perByte - if true, only the bits in each byte are reversed, if false, then all bits in the address are reversed
        Returns:
        Throws:
        IncompatibleAddressException - if this is a subnet that cannot be reversed
      • adjustPrefixBySegment

        IPAddressSegmentSeries adjustPrefixBySegment(boolean nextSegment,
                                                     boolean zeroed)
        Description copied from interface: AddressSegmentSeries
        Increases or decreases prefix length to the next segment boundary.
        Specified by:
        adjustPrefixBySegment in interface AddressSegmentSeries
        Parameters:
        nextSegment - whether to move prefix to previous or following segment coundary
        zeroed - whether the bits that move from one side of the prefix to the other become zero or retain their original values
        Returns:
      • adjustPrefixLength

        IPAddressSegmentSeries 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. When a prefix length is decreased, the bits moved outside the prefix become zero.

        Specified by:
        adjustPrefixLength in interface AddressSegmentSeries
        Returns:
      • adjustPrefixLength

        IPAddressSegmentSeries adjustPrefixLength(int adjustment,
                                                  boolean zeroed)
        Description copied from interface: AddressSegmentSeries
        Increases or decreases prefix length by the given increment.
        Specified by:
        adjustPrefixLength in interface AddressSegmentSeries
        Parameters:
        adjustment - the increment
        zeroed - whether the bits that move from one side of the prefix to the other become zero or retain their original values
        Returns:
      • setPrefixLength

        IPAddressSegmentSeries setPrefixLength(int prefixLength)
        Description copied from interface: AddressSegmentSeries
        Sets the prefix length.

        If this series has a prefix length, and the 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.

        The bits that move from one side of the prefix length to the other (ie bits moved into the prefix or outside the prefix) are zeroed.

        Specified by:
        setPrefixLength in interface AddressSegmentSeries
        Returns:
        See Also:
        AddressSegmentSeries.applyPrefixLength(int)
      • setPrefixLength

        IPAddressSegmentSeries setPrefixLength(int prefixLength,
                                               boolean zeroed)
        Description copied from interface: AddressSegmentSeries
        Sets the prefix length.

        When the prefix is extended beyond the segment series boundary, it is removed.

        Specified by:
        setPrefixLength in interface AddressSegmentSeries
        zeroed - whether the bits that move from one side of the prefix length to the other (ie bits moved into the prefix or outside the prefix) are zeroed.
        Returns: