inet.ipaddr

Class IPAddressSection

    • Method Detail

      • getByteCount

        public int getByteCount()
        Description copied from interface: AddressComponent
        returns the number of bytes in each of the address components represented by this instance
        Specified by:
        getByteCount in interface AddressComponent
        Returns:
      • isIPv4

        public boolean isIPv4()
      • isIPv6

        public boolean isIPv6()
      • getByteIndex

        public abstract int getByteIndex(int networkPrefixLength)
      • getSegmentIndex

        public abstract int getSegmentIndex(int networkPrefixLength)
      • getNetworkSection

        public abstract IPAddressSection getNetworkSection(int networkPrefixLength,
                                                           boolean withPrefixLength)
      • getNetworkSection

        public abstract IPAddressSection getNetworkSection(int networkPrefixLength)
      • getHostSection

        public abstract IPAddressSection getHostSection(int networkPrefixLength)
      • getMaskPrefixLength

        public java.lang.Integer getMaskPrefixLength(boolean network)
        If this address section is equivalent to the mask for a CIDR prefix, it returns that prefix length. Otherwise, it returns null. A CIDR network mask is an address with all 1s in the network section and then all 0s in the host section. A CIDR host mask is an address with all 0s in the network section and then all 1s in the host section. The prefix length is the length of the network section. Also, keep in mind that the prefix length returned by this method is not equivalent to the prefix length used to construct this object. The prefix length used to construct indicates the network and host portion of this address. The prefix length returned here indicates the whether the value of this address can be used as a mask for the network and host portion of any other address. Therefore the two values can be different values, or one can be null while the other is not. This method applies only to the lower value of the range if this section represents multiple values.
        Parameters:
        network - whether to check for a network mask or a host mask
        Returns:
        the prefix length corresponding to this mask, or null if this address is not a CIDR prefix mask
      • getHostBits

        public java.lang.Integer getHostBits()
      • getSegmentPrefixLength

        public static java.lang.Integer getSegmentPrefixLength(int bitsPerSegment,
                                                               java.lang.Integer prefixLength,
                                                               int segmentIndex)
        Across the address prefixes are: IPv6: (null):...:(null):(1 to 16):(0):...:(0) or IPv4: ...(null).(1 to 8).(0)...
      • getSegmentPrefixLength

        public static java.lang.Integer getSegmentPrefixLength(int bitsPerSegment,
                                                               int segmentPrefixedBits)
        Across the address prefixes are: IPv6: (null):...:(null):(1 to 16):(0):...:(0) or IPv4: ...(null).(1 to 8).(0)...
      • contains

        public boolean contains(IPAddressSection other)
        Parameters:
        other -
        Returns:
        whether this subnet contains the given address section
      • isMaskCompatibleWithRange

        public boolean isMaskCompatibleWithRange(IPAddressSection mask,
                                                 java.lang.Integer networkPrefixLength)
        Returns whether the given mask and prefix combination can be used to generate a subnet. See IPAddress#isMaskCompatibleWithRange(IPAddress, Integer)
        Parameters:
        mask -
        networkPrefixLength -
        Returns:
      • toPrefixedEquivalent

        public IPAddressSection toPrefixedEquivalent()
        Returns the CIDR address section for which the range of addresses in this section is specified using just a single value and a prefix length in the returned section. Otherwise, returns null. If this address represents just a single address, this is returned.
        Returns:
      • toMinPrefixedEquivalent

        public IPAddressSection toMinPrefixedEquivalent()
        Constructs an equivalent address section with the smallest CIDR prefix length possible (largest network), such that the address represents the exact same range of addresses.
        Returns:
      • removePrefixLength

        public abstract IPAddressSection removePrefixLength(boolean zeroed)
      • setPrefixLength

        public abstract IPAddressSection setPrefixLength(int prefixLength,
                                                         boolean zeroed)
      • getEquivalentPrefix

        public java.lang.Integer getEquivalentPrefix()
        Returns a prefix length for which the range of this address section can be specified only using the section's lower value and the prefix length If no such prefix exists, returns null If this address section represents a single value, returns the bit length
        Specified by:
        getEquivalentPrefix in interface AddressDivisionSeries
        Overrides:
        getEquivalentPrefix in class IPAddressDivisionGrouping
        Returns:
        the prefix length or null
      • getLower

        public abstract IPAddressSection getLower()
        If this represents an address section with ranging values, returns an address section representing the lower values of the range If this represents an address section with a single value in each segment, returns this.
        Specified by:
        getLower in interface AddressComponent
        Specified by:
        getLower in interface AddressSection
        Specified by:
        getLower in interface AddressSegmentSeries
        Returns:
      • getUpper

        public abstract IPAddressSection getUpper()
        If this represents an address section with ranging values, returns an address section representing the upper values of the range If this represents an address section with a single value in each segment, returns this.
        Specified by:
        getUpper in interface AddressComponent
        Specified by:
        getUpper in interface AddressSection
        Specified by:
        getUpper in interface AddressSegmentSeries
        Returns:
      • isEntireAddress

        public boolean isEntireAddress()
      • getSegmentStrings

        public java.lang.String[] getSegmentStrings()
      • toFullString

        public abstract 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.
      • toCompressedString

        public abstract java.lang.String toCompressedString()
        This produces the shortest valid string. For subnets the string will not have wildcards in host segments (there will be zeros instead), only in network segments.
        Specified by:
        toCompressedString in interface AddressSegmentSeries
        Returns:
      • toPrefixLengthString

        public abstract 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

        public abstract 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

        public abstract 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

        public abstract 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

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

        public abstract java.lang.String toSQLWildcardString()
        This is the same as the string from toNormalizedWildcardString except that: -it uses IPAddress.SEGMENT_SQL_WILDCARD instead of IPAddress.SEGMENT_WILDCARD -it uses IPAddress.SEGMENT_SQL_SINGLE_WILDCARD
      • toReverseDNSLookupString

        public abstract 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:
      • toBinaryString

        public java.lang.String toBinaryString()
        Writes this address section 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

        public java.lang.String toOctalString(boolean with0Prefix)
        Writes this address as a single hexadecimal value with always the exact same number of characters, with or without a preceding 0x prefix. For IPv4 there are 8 hex characters, for IPv6 there are 32 hex 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.
      • toHexString

        public java.lang.String toHexString(boolean with0xPrefix)
        Writes this address as a single hexadecimal value with always the exact same number of characters, with or without a preceding 0x prefix. For IPv4 there are 8 hex characters, for IPv6 there are 32 hex 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.
        Specified by:
        toHexString in interface AddressComponent
      • toStandardStringCollection

        public IPAddressPartStringCollection toStandardStringCollection()
        Returns at most a couple dozen string representations: -mixed (1:2:3:4:5:6:1.2.3.4) -upper and lower case -full compressions or no compression (a:0:0:c:d:0:e:f or a::c:d:0:e:f or a:0:b:c:d::e:f) -full leading zeros (000a:0000:000b:000c:000d:0000:000e:000f) -combinations thereof
        Returns:
      • toAllStringCollection

        public IPAddressPartStringCollection toAllStringCollection()
        Use this method with care... a single IPv6 address can have thousands of string representations. Examples: "::" has 1297 such variations, but only 9 are considered standard "a:b:c:0:d:e:f:1" has 1920 variations, but only 12 are standard Variations included in this method: -all standard variations -choosing specific segments for full leading zeros (::a:b can be ::000a:b, ::a:000b, or ::000a:000b) -choosing which zero-segments to compress (0:0:a:: can be ::a:0:0:0:0:0 or 0:0:a::) -mixed representation (1:2:3:4:5:6:1.2.3.4) -all combinations of such variations Variations omitted from this method: -mixed case of a-f, which you can easily handle yourself with String.equalsIgnoreCase -adding a variable number of leading zeros (::a can be ::0a, ::00a, ::000a) -choosing any number of zero-segments anywhere to compress (:: can be 0:0:0::0:0)
        Returns:
      • toDatabaseSearchStringCollection

        public IPAddressPartStringCollection toDatabaseSearchStringCollection()
        Returns a set of strings for search the standard string representations in a database -compress the largest compressible segments or no compression (a:0:0:c:d:0:e:f or a::c:d:0:e:f) -upper/lowercase is not considered because many databases are case-insensitive
        Returns:
      • getStartsWithSQLClause

        public void getStartsWithSQLClause(java.lang.StringBuilder builder,
                                           java.lang.String expression)
        This method gives you an SQL clause that allows you to search the database for the front part of an address or addresses in a given network. This is not as simple as it sounds, because the same address can be written in different ways (especially for IPv6) and in addition, addresses in the same network can have different beginnings (eg 1.0.0.0/7 are all addresses from 0.0.0.0 to 1.255.255.255), so you can see they start with both 1 and 0. You can reduce the number of possible beginnings by choosing a segment boundary for the network prefix. The SQL produced works for MySQL. For a different database type, use getStartsWithSQLClause(StringBuilder, String, IPAddressSQLTranslator)
        Parameters:
        builder -
        expression - the expression that must match the condition, whether a column name or other
      • getStartsWithSQLClause

        public void getStartsWithSQLClause(java.lang.StringBuilder builder,
                                           java.lang.String expression,
                                           IPAddressSQLTranslator translator)